brh986 Posted November 18, 2009 Share Posted November 18, 2009 Can anyone tell me how to fix this error message? I don't really know anything about php - I used another tool to create the form but their help forum sucks (very little activity). I generally know what an undefined variable in general programming terms but i don't know how to properly define it and make the form work. Notice: Undefined variable: field_12_filename in /home/icr/public_html/CVSubForm/processor.php on line 36 The contents of processor.php below: <?php $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); session_start(); if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) { // File upload handling if($_FILES['field_12']['name']!=''){ $field_12_filename = "file_12_".date("sihdmY").substr($_FILES['field_12']['name'],strlen($_FILES['field_12']['name'])-4); if(!move_uploaded_file($_FILES['field_12']['tmp_name'], "./files/".$field_12_filename)){ die("File " . $_FILES['field_12']['name'] . " was not uploaded."); } } // File upload handling if($_FILES['field_13']['name']!=''){ $field_13_filename = "file_13_".date("sihdmY").substr($_FILES['field_13']['name'],strlen($_FILES['field_13']['name'])-4); if(!move_uploaded_file($_FILES['field_13']['tmp_name'], "./files/".$field_13_filename)){ die("File " . $_FILES['field_13']['name'] . " was not uploaded."); } } mail("[email protected]","CV Submission from Website","Form data: Name:: " . $_POST['field_1'] . " Street Address:: " . $_POST['field_2'] . " Floor / Apartment / Suite:: " . $_POST['field_3'] . " City:: " . $_POST['field_4'] . " State / Province:: " . $_POST['field_5'] . " Post Code:: " . $_POST['field_6'] . " Country:: " . $_POST['field_7'] . " Telephone:: " . $_POST['field_8'] . " E-Mail:: " . $_POST['field_9'] . " Field of Interest(s):: " . $_POST['field_10'] . " Position Applying For (if Applicable):: " . $_POST['field_11'] . " Cover Letter:: ".$where_form_is."files/".$field_12_filename." (original file name: " . $_FILES['field_12']['name'] . ") CV:: ".$where_form_is."files/".$field_13_filename." (original file name: " . $_FILES['field_13']['name'] . ") powered by phpFormGenerator. "); include("confirm.html"); } else { echo "Invalid Captcha String."; } ?> Here's the HTML for the form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title> CV Submission </title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><link href="style.css" rel="stylesheet" type="text/css"> <!-- calendar stuff --> <link rel="stylesheet" type="text/css" href="calendar/calendar-blue2.css" /> <script type="text/javascript" src="calendar/calendar.js"></script> <script type="text/javascript" src="calendar/calendar-en.js"></script> <script type="text/javascript" src="calendar/calendar-setup.js"></script> <!-- END calendar stuff --> <!-- expand/collapse function --> <SCRIPT type=text/javascript> <!-- function collapseElem(obj) { var el = document.getElementById(obj); el.style.display = 'none'; } function expandElem(obj) { var el = document.getElementById(obj); el.style.display = ''; } //--> </SCRIPT> <!-- expand/collapse function --> <!-- expand/collapse function --> <SCRIPT type=text/javascript> <!-- // collapse all elements, except the first one function collapseAll() { var numFormPages = 1; for(i=2; i <= numFormPages; i++) { currPageId = ('mainForm_' + i); collapseElem(currPageId); } } //--> </SCRIPT> <!-- expand/collapse function --> <!-- validate --> <SCRIPT type=text/javascript> <!-- function validateField(fieldId, fieldBoxId, fieldType, required) { fieldBox = document.getElementById(fieldBoxId); fieldObj = document.getElementById(fieldId); if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website') { if(required == 1 && fieldObj.value == '') { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state') { if(required == 1 && fieldObj.selectedIndex == 0) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } else if(fieldType == 'email') { if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value))) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } } function validate_email(emailStr) { apos=emailStr.indexOf("@"); dotpos=emailStr.lastIndexOf("."); if (apos<1||dotpos-apos<2) { return false; } else { return true; } } function validateDate(fieldId, fieldBoxId, fieldType, required, minDateStr, maxDateStr) { retValue = true; fieldBox = document.getElementById(fieldBoxId); fieldObj = document.getElementById(fieldId); dateStr = fieldObj.value; if(required == 0 && dateStr == '') { return true; } if(dateStr.charAt(2) != '/' || dateStr.charAt(5) != '/' || dateStr.length != 10) { retValue = false; } else // format's okay; check max, min { currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30 + parseInt(dateStr.substr(6,4),10)*365; //alert(currDays); if(maxDateStr != '') { maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30 + parseInt(maxDateStr.substr(6,4),10)*365; //alert(maxDays); if(currDays > maxDays) retValue = false; } if(minDateStr != '') { minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30 + parseInt(minDateStr.substr(6,4),10)*365; //alert(minDays); if(currDays < minDays) retValue = false; } } if(retValue == false) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } //--> </SCRIPT> <!-- end validate --> </head> <body onLoad="collapseAll()"> <div id="mainForm"> <div id="formHeader"> <h2 class="formInfo"></h2> <p class="formInfo"></p> </div> <BR/><!-- begin form --> <form method=post enctype=multipart/form-data action=processor.php onSubmit="return validatePage1();"><ul class=mainForm id="mainForm_1"> <li class="mainForm" id="fieldBox_1"> <label class="formFieldQuestion">Name: *</label><input class=mainForm type=text name=field_1 id=field_1 size='20' value=''></li> <li class="mainForm" id="fieldBox_2"> <label class="formFieldQuestion">Street Address: *</label><input class=mainForm type=text name=field_2 id=field_2 size='20' value=''></li> <li class="mainForm" id="fieldBox_3"> <label class="formFieldQuestion">Floor / Apartment / Suite:</label><input class=mainForm type=text name=field_3 id=field_3 size='20' value=''></li> <li class="mainForm" id="fieldBox_4"> <label class="formFieldQuestion">City: *</label><input class=mainForm type=text name=field_4 id=field_4 size='20' value=''></li> <li class="mainForm" id="fieldBox_5"> <label class="formFieldQuestion">State / Province:</label><input class=mainForm type=text name=field_5 id=field_5 size='20' value=''></li> <li class="mainForm" id="fieldBox_6"> <label class="formFieldQuestion">Post Code: *</label><input class=mainForm type=text name=field_6 id=field_6 size='20' value=''></li> <li class="mainForm" id="fieldBox_7"> <label class="formFieldQuestion">Country: *</label><input class=mainForm type=text name=field_7 id=field_7 size='20' value=''></li> <li class="mainForm" id="fieldBox_8"> <label class="formFieldQuestion">Telephone: *</label><input class=mainForm type=text name=field_8 id=field_8 size='20' value=''></li> <li class="mainForm" id="fieldBox_9"> <label class="formFieldQuestion">E-Mail: *</label><input class=mainForm type=text name=field_9 id=field_9 size='20' value=''></li> <li class="mainForm" id="fieldBox_10"> <label class="formFieldQuestion">Field of Interest(s): *</label><input class=mainForm type=text name=field_10 id=field_10 size='20' value=''></li> <li class="mainForm" id="fieldBox_11"> <label class="formFieldQuestion">Position Applying For (if Applicable):</label><input class=mainForm type=text name=field_11 id=field_11 size='20' value=''></li> <li class="mainForm" id="fieldBox_12"> <label class="formFieldQuestion">Cover Letter:</label><input class=mainForm type=file name=field_12 id=field_12 value=""></li> <li class="mainForm" id="fieldBox_13"> <label class="formFieldQuestion">CV: *</label><input class=mainForm type=file name=field_13 id=field_13 value=""></li> <!-- end of this page --> <!-- page validation --> <SCRIPT type=text/javascript> <!-- function validatePage1() { retVal = true; if (validateField('field_1','fieldBox_1','text',1) == false) retVal=false; if (validateField('field_2','fieldBox_2','text',1) == false) retVal=false; if (validateField('field_3','fieldBox_3','text',0) == false) retVal=false; if (validateField('field_4','fieldBox_4','text',1) == false) retVal=false; if (validateField('field_5','fieldBox_5','text',0) == false) retVal=false; if (validateField('field_6','fieldBox_6','text',1) == false) retVal=false; if (validateField('field_7','fieldBox_7','text',1) == false) retVal=false; if (validateField('field_8','fieldBox_8','text',1) == false) retVal=false; if (validateField('field_9','fieldBox_9','text',1) == false) retVal=false; if (validateField('field_10','fieldBox_10','text',1) == false) retVal=false; if (validateField('field_11','fieldBox_11','text',0) == false) retVal=false; if (validateField('field_12','fieldBox_12','file',0) == false) retVal=false; if (validateField('field_13','fieldBox_13','file',1) == false) retVal=false; if(retVal == false) { alert('Please correct the errors. Fields marked with an asterisk (*) are required'); return false; } return retVal; } //--> </SCRIPT> <!-- end page validaton --> <!-- next page buttons --><li class="mainForm"> <label class="formFieldQuestion"> Type the following: <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>For security purposes, please type the letters in the image.</span></a><BR><img src="CaptchaSecurityImages.php" /> </label> <input id="captchaForm" name="security_code" class="mainForm" type="text"/> </li><li class="mainForm"> <input id="saveForm" class="mainForm" type="submit" value="Submit" /> </li> </form> <!-- end of form --> <!-- close the display stuff for this page --> </ul></div><div id="footer"><p class="footer"><a class=footer href=http://phpformgen.sourceforge.net>Generated by phpFormGenerator</a></p></div> </body> </html> There is another php file called install.php that came with this but I don't know what it does: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title> CV Submission </title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><link href="style.css" rel="stylesheet" type="text/css"> <!-- calendar stuff --> <link rel="stylesheet" type="text/css" href="calendar/calendar-blue2.css" /> <script type="text/javascript" src="calendar/calendar.js"></script> <script type="text/javascript" src="calendar/calendar-en.js"></script> <script type="text/javascript" src="calendar/calendar-setup.js"></script> <!-- END calendar stuff --> <!-- expand/collapse function --> <SCRIPT type=text/javascript> <!-- function collapseElem(obj) { var el = document.getElementById(obj); el.style.display = 'none'; } function expandElem(obj) { var el = document.getElementById(obj); el.style.display = ''; } //--> </SCRIPT> <!-- expand/collapse function --> <!-- expand/collapse function --> <SCRIPT type=text/javascript> <!-- // collapse all elements, except the first one function collapseAll() { var numFormPages = 1; for(i=2; i <= numFormPages; i++) { currPageId = ('mainForm_' + i); collapseElem(currPageId); } } //--> </SCRIPT> <!-- expand/collapse function --> <!-- validate --> <SCRIPT type=text/javascript> <!-- function validateField(fieldId, fieldBoxId, fieldType, required) { fieldBox = document.getElementById(fieldBoxId); fieldObj = document.getElementById(fieldId); if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website') { if(required == 1 && fieldObj.value == '') { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state') { if(required == 1 && fieldObj.selectedIndex == 0) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } else if(fieldType == 'email') { if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value))) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } } function validate_email(emailStr) { apos=emailStr.indexOf("@"); dotpos=emailStr.lastIndexOf("."); if (apos<1||dotpos-apos<2) { return false; } else { return true; } } function validateDate(fieldId, fieldBoxId, fieldType, required, minDateStr, maxDateStr) { retValue = true; fieldBox = document.getElementById(fieldBoxId); fieldObj = document.getElementById(fieldId); dateStr = fieldObj.value; if(required == 0 && dateStr == '') { return true; } if(dateStr.charAt(2) != '/' || dateStr.charAt(5) != '/' || dateStr.length != 10) { retValue = false; } else // format's okay; check max, min { currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30 + parseInt(dateStr.substr(6,4),10)*365; //alert(currDays); if(maxDateStr != '') { maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30 + parseInt(maxDateStr.substr(6,4),10)*365; //alert(maxDays); if(currDays > maxDays) retValue = false; } if(minDateStr != '') { minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30 + parseInt(minDateStr.substr(6,4),10)*365; //alert(minDays); if(currDays < minDays) retValue = false; } } if(retValue == false) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } //--> </SCRIPT> <!-- end validate --> </head> <body onLoad="collapseAll()"> <div id="mainForm"> <div id="formHeader"> <h2 class="formInfo"></h2> <p class="formInfo"></p> </div> <BR/><div id="footer"><p class="footer"><a class=footer href=http://phpformgen.sourceforge.net>Generated by phpFormGenerator</a></p></div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/181997-help-needed-with-error-on-php-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2009 Share Posted November 18, 2009 The code that defines the variable in question is inside of a conditional statement that evaluates as FALSE, so the variable does not exist. Later, the code unconditionally references the variable in question, producing the undefined variable error. The code that is unconditionally referencing the variable either needs to be put inside a conditional statement if the variable is optional and it might not exist (edit: or you need to define the variable in question with a suitable default value at the start of the code) or if the variable should always exist, you would need to find out why the $_FILES['field_12']['name'] was an empty string and is causing the variable to not exist. Quote Link to comment https://forums.phpfreaks.com/topic/181997-help-needed-with-error-on-php-form/#findComment-959980 Share on other sites More sharing options...
brh986 Posted November 18, 2009 Author Share Posted November 18, 2009 The code that defines the variable in question is inside of a conditional statement that evaluates as FALSE, so the variable does not exist. Later, the code unconditionally references the variable in question, producing the undefined variable error. The code that is unconditionally referencing the variable either needs to be put inside a conditional statement if the variable is optional and it might not exist (edit: or you need to define the variable in question with a suitable default value at the start of the code) or if the variable should always exist, you would need to find out why the $_FILES['field_12']['name'] was an empty string and is causing the variable to not exist. For the most part you are talking over my head. The code it seems to be talking about seems to refer to the field "Cover Letter:" which is a file attachment that should be optional. Can you tell me what to change to make this work? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/181997-help-needed-with-error-on-php-form/#findComment-960010 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 the error in question is on line 36, yet you posted every single line of your script, including ALL the completely irrelevant javascript, etc. you gotta think about these things before posting. i'm saying this because i read the first couple of lines, and that was all. so if you had written anything below those lines, i didn't read it. now, your issue is as PFMaBiSmAd said. you are calling a variable which has not been defined. this is only a notice and will not bring your script to a halt, however, it is telling you something. as well, the notice is pretty self-explanatory when it says, "Undefined variable: variable_name_here", which means, the variable in question hasn't been defined. you need to give that variable a conditional value if you are intent on using it in the script. Quote Link to comment https://forums.phpfreaks.com/topic/181997-help-needed-with-error-on-php-form/#findComment-960015 Share on other sites More sharing options...
brh986 Posted November 18, 2009 Author Share Posted November 18, 2009 the error in question is on line 36, yet you posted every single line of your script, including ALL the completely irrelevant javascript, etc. you gotta think about these things before posting. i'm saying this because i read the first couple of lines, and that was all. so if you had written anything below those lines, i didn't read it. As i explained in the first line I don't know anything about this therefore I don't know which parts of the code are relevant and which not. From basic programming knowledge I know that the actual problem is rarely on the line that gives the error, it's often before or somewhere else. now, your issue is as PFMaBiSmAd said. you are calling a variable which has not been defined. this is only a notice and will not bring your script to a halt, however, it is telling you something. as well, the notice is pretty self-explanatory when it says, "Undefined variable: variable_name_here", which means, the variable in question hasn't been defined. you need to give that variable a conditional value if you are intent on using it in the script. I got that as well - what do I need to change in the code to make it work? As I explained in my reply this is an option field. Quote Link to comment https://forums.phpfreaks.com/topic/181997-help-needed-with-error-on-php-form/#findComment-960019 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.