Hi there. I have a pretty complicated form designed for Joomla where the form input boxes combine all user data and some html to create an article in Joomla. It uses php and js. I am almost finished but have hit a snag.
There is a file upload portion in the form. When the file is uploaded upon submit, a php function is triggered which creates a unique file name for that file and uploads it into one folder. I need to be able to catch that variable BEFORE submission, transfer it to a js variable, and inserted back into the hidden field value which is the html creation. My js portion of the form takes all form fields onblur and copies them into my hidden variable which is then passed onsubmit into the db as one long html article. But if I add in this variable converted to js, when the onblur is triggered, it prematurely triggers the php function and I suffenly get a white screen. how can I pass the variable as soon as a file is entered into the box without refreshing the screen or submitting?
The php function variable I need is called $attachments['file_13'']
Passing PHP Session Variable to JS Without Form Submission
Moderator: General Moderators
Re: Passing PHP Session Variable to JS Without Form Submission
Okay, no help yet. Here is another way of asking. I have done some research but not sure how to proceed.
I have a php form which also uses js. The form allows for upload attachments. On submit, the form accesses a php set of functions and one of those functions is for the upload attachments which is:
This function renames the file. I need to be able to get the name of this file for my form before it is submitted because it is needed to be placed in the html of the hidden form field. The rest of the form field which are filled out by the user are transferred to a hidden field using js mixed with html. You might ask why I am doing it this way...it is a joomla site and any other way would entail modification of the core content component which I don't want to do.
So.....any thoughts? Maybe have this upload function post to a text file or use ajax? I don't know how though...
I have a php form which also uses js. The form allows for upload attachments. On submit, the form accesses a php set of functions and one of those functions is for the upload attachments which is:
Code: Select all
/**
* Upload attachments
*/
$attachments = array();
if ( trim($paramsvalues->uploads == 'Yes' ) && trim($paramsvalues->uploadfields) ) {
//$allowed_s1 = explode(",", trim($paramsvalues->uploadfields));
if ( is_array($paramsvalues->uploadfields) ) {
$allowed_s1 = implode('|', $paramsvalues->uploadfields);
} else {
$allowed_s1 = $paramsvalues->uploadfields;
}
$allowed_s1 = explode(",", trim($allowed_s1));
foreach ( $allowed_s1 as $allowed_1 ) {
$allowed_s2 = explode(":", trim($allowed_1));
$allowed_s3 = explode("|", trim($allowed_s2[1]));
$allowed_s4 = explode("{", trim($allowed_s3[count($allowed_s3) - 1]));
$allowed_s3[count($allowed_s3) - 1] = $allowed_s4[0];
$allowed_s5 = explode("-", str_replace('}', '', trim($allowed_s4[1])));
$original_name = $_FILES[$allowed_s2[0]]['tmp_name'];
$filename = date('YmdHis').'_'.preg_replace('`[^a-z0-9-_.]`i','',$_FILES[$allowed_s2[0]]['name']);
$fileok = true;
if ( $original_name ) {
if ( ($_FILES[$allowed_s2[0]]["size"] / 1024) > trim($allowed_s5[0]) ) {
$fileok = false;
$session->set("chrono_verification_msg", 'Sorry, Your uploaded file size exceeds the allowed limit.', md5('chrono'));
showform($_POST);
return;
}
if ( ($_FILES[$allowed_s2[0]]["size"] / 1024) < trim($allowed_s5[1]) ) {
$fileok = false;
$session->set("chrono_verification_msg", 'Sorry, Your uploaded file size is less than the allowed limit', md5('chrono'));
showform($_POST);
return;
}
$fn = $_FILES[$allowed_s2[0]]['name'];
$fext = substr($fn, strrpos($fn, '.') + 1);
if ( !in_array(strtolower($fext), $allowed_s3) ) {
$fileok = false;
$session->set("chrono_verification_msg", 'Sorry, Your uploaded file type is not allowed', md5('chrono'));
showform($_POST);
return;
}
if ( $fileok ) {
$uploadedfile = handle_uploaded_files($original_name, $filename);
$_POST[$allowed_s2[0]] = $filename;
if ( $uploadedfile ) {
$attachments[$allowed_s2[0]] = $uploadedfile;
}
}
}
}
}So.....any thoughts? Maybe have this upload function post to a text file or use ajax? I don't know how though...