kokomo310 Posted March 14, 2007 Share Posted March 14, 2007 There is probably an easy solution for this, but I cannot find it anywhere! I have a form in which several fields are required, two of which use drop down menus and require a selection to be made (location and favorite entree). Even though the field names are included in the html code as required, if a selection is not made the form is still processing. Further, the missing fields are not showing up in the resulting error page or error email. I have tested the form by leaving all fields blank and trying to submit and all fields show up as missing EXCEPT the fields from the drop down menus. example code (abbreviated to save space) ======================= <input type="hidden" name="required" value="realname,address,city,state,zip,telephone,email, age,sex,last_visit,location,favorite_entree,food-quality,service,overall,value"> <select name="location"> <option selected value="Pick One...">Choose a Location</option> <option value="Vancouver, WA - SE Mill Plain Blvd">Vancouver, WA - SE Mill Plain Blvd</option> <option value="American Fork, UT - East State Road">American Fork, UT - East State Road</option> </select> <select name="favorite_entree"> <option selected value="Pick One...">Choose One</option> <option value="Ribs">Ribs</option> <option value="Pork">Pork</option> <option value="Beef">Beef</option> <option value="Chicken">Chicken</option> <option value="Turkey">Turkey</option> <option value="Salad">Salad</option> </select> error email========================== The following error occurred in FormMail: missing_fields Error=The form required some values that you did not seem to provide. realname address city state zip telephone email age sex last_visit food-quality service overall value address: '' address2: '' city: '' state: '' zip: '' telephone: '' age: '' last_visit: '' servers_name: '' location: 'Pick One...' favorite_entree: 'Pick One...' improvements: " Submit: 'Submit' FYI - Someone advised me to add "[]" after the select name (location[]). I tried this and it did cause the field to show up as missing in the error page & email when no selection was made, but it caused a new problem. After adding brackets, even when selection was made the fields showed up as missing. Quote Link to comment Share on other sites More sharing options...
interpim Posted March 14, 2007 Share Posted March 14, 2007 if(!isset($_POST['favorite_entree[]'])){ error; } i think lol Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 I am using formmail.php (tectite). Wondering if that will screw with the error page if I try to validate only one field using that code? Would I have to include the code for each required field? Thanks! Quote Link to comment Share on other sites More sharing options...
interpim Posted March 14, 2007 Share Posted March 14, 2007 with the "Select One" listed it will always read it as having a value... perhaps leaving that out and not setting a selected value to the form will fix your problem Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 if(isset($_POST)){ if(empty($_POST['favorite_entree']) || empty($_POST['location'])){ echo "You have not entered in all the required fields. Please try again.<br />\n"; exit; } } and like interpim said, your default options listed should not have a value, like this: <option value="">Choose One</option> and as long as it is the first option in the html dropdown, you don't need to specify that it is selected. Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 Actually tried that already and it didn't help... Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 b00_lolly, would I totally replace the error reporting method included with formmail.php and use the code below? Would I include every required field? Just wondering if this way of reporting missing fields will conflict with the rest of the script. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 b00_lolly, would I totally replace the error reporting method included with formmail.php and use the code below? Would I include every required field? Just wondering if this way of reporting missing fields will conflict with the rest of the script. in order to give you an accurate/correct answer, i'd have to see the entire script, and i'd also need to know which fields are 'required' to allow your form to be processed properly. Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 formmail code: http://www.ribcity.com/example-formmail.txt You can view the form itself at: http://www.ribcity.com/survey.html Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 that is WAY too much code to read through. the best way to see if it will mess up the existing code is to just try it. it looks like all of the fields are necessary (and it looks like you're adding new fields to the existing form), so all you'd have to do, is find where it checks to see if the form fields were entered within the EXISTING code, and just add your fields to that existing if statement. make sense? Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 Yeah, I think so. Let me try and see if I can work it out that way. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 The code you gave me didn't conflict with the script, it was just ignored and the normal error screen pulled up. I think the following is the only part of the formmail script I need to modify, but I am not very good with php which I'm sure you can tell, so I'm not sure how to modify using your code... original formmail script ========= if (!CheckRequired($SPECIAL_VALUES["required"],$aAllRawValues,$missing,$a_missing_list)) UserError("missing_fields", "The form required some values that you did not seem to provide.", $missing,$a_missing_list); Thanks again for all your help, Kim Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 good job kokomo! i double checked the script and you are correct. that is where it checks for input in the required fields... so what you want to do, is replace that snippet of code with this... if (!CheckRequired($SPECIAL_VALUES["required"],$aAllRawValues,$missing,$a_missing_list, $_POST['favorite_entree'], $_POST['location'])) UserError("missing_fields", "The form required some values that you did not seem to provide.", $missing,$a_missing_list); Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 I replaced the code but it didn't work. Same thing, if I submit the form blank, all fields show as missing except those. Dang! Do you think the problem is being caused by the fact that I included "choose one" as the first option for the locations menu, thereby providing a selection by default? Problem is, if I take that out then the menu will simply start with one of the locations and that would be a selection too. ??? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 14, 2007 Share Posted March 14, 2007 You probably need to take a look at the CheckRequired() function, to see what it takes for arguments. By looking I would guess that it takes an array of fieldnames and an array of the posted data, but I can't be sure. Anyways, you'd need to get your fieldnames added to that array. EDIT: Ok I actually decided to *look* at the code... The first parameter is a comma separated list of field names. It looks like this is where the variable starts being set:: <?php // // SPECIAL_FIELDS is the list of fields that formmail.php looks for to // control its operation // $SPECIAL_FIELDS = array( "email", // email address of the person who filled in the form "realname", // the real name of the person who filled in the form "recipients", // comma-separated list of email addresses to which we'll send the results "cc", // comma-separated list of email addresses to which we'll CC the results "bcc", // comma-separated list of email addresses to which we'll BCC the results "required", // comma-separated list of fields that must be found in the input "conditions", // complex condition tests "mail_options", // comma-separated list of options "good_url", // URL to go to on success "good_template",// template file to display on success "bad_url", // URL to go to on error "bad_template", // template file to display on error "template_list_sep", // separator when expanding lists in templates "this_form", // the URL of the form (can be used by bad_url) "subject", // subject for the email "env_report", // comma-separated list of environment variables to report "filter", // a support filter to use "logfile", // log file to write to "csvfile", // file to write CSV records to "csvcolumns", // columns to save in the csvfile "crm_url", // URL for sending data to the CRM; note that the // value must have a valid prefix specified in TARGET_URLS "crm_spec", // CRM specification (field mapping) "crm_options", // comma-separated list of options to control CRM processing "derive_fields", // a list of fields to derive from other fields "autorespond", // specification for auto-responding "arverify", // verification field to allow auto-responding "alert_to"); // email address to send alerts (errors) to ?> Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 I believe everything is in the array: <input type="hidden" name="required" value="realname,address,city,state,zip,telephone,email, age,sex,last_visit,location,favorite_entree,food-quality,service,overall,value"> Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 Oh... So you are saying I need to add the two fields in question to the special_fields array in addition to the required section of the html? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 14, 2007 Share Posted March 14, 2007 No you are correct, I didn't look at the HTML at first (as a side note, unless I am missing something that is an extremely insecure form). But looking at the HTML there are still values for the default options: <option selected value="Pick one...">Choose One</option> That will cause the fields to pass any checking done, since as far as the script is concerned, there is a value sent for those fields. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 Do you think the problem is being caused by the fact that I included "choose one" as the first option for the locations menu, thereby providing a selection by default? no that's not the problem. leave the value in your <option> tag blank as i've showed you. the if statement is working properly as well, but now you need to add those errors to the array that stores the empty required fields. this is going to get a little tricky from here as it is a very complicated script. here's the array in the script: $SPECIAL_FIELDS = array( "email", // email address of the person who filled in the form "realname", // the real name of the person who filled in the form "recipients", // comma-separated list of email addresses to which we'll send the results "cc", // comma-separated list of email addresses to which we'll CC the results "bcc", // comma-separated list of email addresses to which we'll BCC the results "required", // comma-separated list of fields that must be found in the input "conditions", // complex condition tests "mail_options", // comma-separated list of options "good_url", // URL to go to on success "good_template",// template file to display on success "bad_url", // URL to go to on error "bad_template", // template file to display on error "template_list_sep", // separator when expanding lists in templates "this_form", // the URL of the form (can be used by bad_url) "subject", // subject for the email "env_report", // comma-separated list of environment variables to report "favorite_entree", #your form field "location", #your form field "filter", // a support filter to use "logfile", // log file to write to "csvfile", // file to write CSV records to "csvcolumns", // columns to save in the csvfile "crm_url", // URL for sending data to the CRM; note that the // value must have a valid prefix specified in TARGET_URLS "crm_spec", // CRM specification (field mapping) "crm_options", // comma-separated list of options to control CRM processing "derive_fields", // a list of fields to derive from other fields "autorespond", // specification for auto-responding "arverify", // verification field to allow auto-responding "alert_to"); // email address to send alerts (errors) to i've added "favorite_entree" and "location" to this array for you. however, that is not all you have to do. somewhere in the script it checks for the required input fields (this is not the if statement we have edited before). the reason there is more work to be done is because the script needs a way to affilliate your new form fields with that specific error in the array. <-- that is the if statement you need to look for (if it IS an 'if' statement). it may have something to do with the $missing or $a_missing_list variables... that will take a good amount of research. let us know what you dig up, we can help you from there. Quote Link to comment Share on other sites More sharing options...
kokomo310 Posted March 14, 2007 Author Share Posted March 14, 2007 Have to run out and need to read your post slowly. I'll be back! Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 14, 2007 Share Posted March 14, 2007 I don't think that those field names need to be added to the array, as they're added to the "required" element from the hidden field on the form. EDIT: I just double checked, it's definately the values you have set for your default dropdown selections. Make sure both of those are value="" I tried it and it returned a list of the missing values, including location and favorite_entree. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 re I don't think that those field names need to be added to the array, as they're added to the "required" element from the hidden field on the form. EDIT: I just double checked, it's definately the values you have set for your default dropdown selections. Make sure both of those are value="" I tried it and it returned a list of the missing values, including location and favorite_entree. read earlier posts. kokomo has already made those changes. Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 14, 2007 Share Posted March 14, 2007 I know he said he tried it... But I downloaded his form, pointed it to his formmail.php script, and changed only those 2 things to be value="", and it worked. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 14, 2007 Share Posted March 14, 2007 I know he said he tried it... But I downloaded his form, pointed it to his formmail.php script, and changed only those 2 things to be value="", and it worked. no shit?! badass bwobhinski! good job! you mean the error handling worked as well? it printed location and favorite_entree?? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 14, 2007 Share Posted March 14, 2007 Yep it all works just fine. And give the credit to Interpim, he spotted it right off. Quote Link to comment 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.