prettikittie Posted July 16, 2009 Share Posted July 16, 2009 Hi, I've been searching everywhere to find the fix for my drop down issue, but sadly, I can't seem to grasp it. I'm fairly new at php. I'm simply trying to get the drop down menu of my form to email the selected option but to no avail, the 'Location' is always returned to me empty. Somehow, I ended up with the answer 'Submit' with one of my attempts. I'd really appreciate any help/insight into what I'm doing wrong ... Thanks muchly ~` I'll only include the sections that are obviously not correct ... and I've only one location example on there. Thanks again. <?php $EmailFrom = "$Name"; $EmailTo = "xxx"; $Subject = ""; $Name = Trim(stripslashes($_POST['Name'])); $Phone = Trim(stripslashes($_POST['Phone'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); $Message = ""; foreach ($_POST as $Locations => $Texas) { $Message .= $Locations . ": " . $Texas . "\n"; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Location: "; $Body .= $Location; $Body .= "\n"; $Body .= "Request: "; $Body .= $Request; $Body .= "\n"; Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/ Share on other sites More sharing options...
WolfRage Posted July 16, 2009 Share Posted July 16, 2009 Let's see the form. Also why are you setting message to equal an empty string after you had already set it to equal the post variable. Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876516 Share on other sites More sharing options...
prettikittie Posted July 16, 2009 Author Share Posted July 16, 2009 Hi, thanks for the reply ... That section of the form is: <strong>Location:</strong> <br /> <select name="Locations"> <option value=" "> </option> <option value="Texas">Texas</option> <option value="Florida">Florida</option> <option value="Maine">Maine</option> </select> Thanks for your help. The code looks the way it does because I'm not sure of how to do it Lol The drop down thing has me stumped! Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876529 Share on other sites More sharing options...
WolfRage Posted July 16, 2009 Share Posted July 16, 2009 OK well you never retrieved this: <?php $locations= htmlspclchars(Trim(stripslashes$_POST['Locations']))); ?> Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876532 Share on other sites More sharing options...
prettikittie Posted July 16, 2009 Author Share Posted July 16, 2009 I've no php at all in the form ... If I try placing this above that section - how to I edit this properly: <?php $EmailFrom = "$Name"; $EmailTo = "xxx"; $Subject = ""; $Name = Trim(stripslashes($_POST['Name'])); $Phone = Trim(stripslashes($_POST['Phone'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); $Message = ""; foreach ($_POST as $Locations => $Texas) { $Message .= $Locations . ": " . $Texas . "\n"; It keeps giving me an error once I remove the empty string, I don't think I'm using the ';' and such correctly. Sorry, I followed a tutorial for the form, however it didn't have any drop-downs in it ~ Thanks, Jen Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876551 Share on other sites More sharing options...
WolfRage Posted July 16, 2009 Share Posted July 16, 2009 <?php $EmailFrom = "$Name"; $EmailTo = "xxx"; $Subject = ""; $locations= htmlspclchars(Trim(stripslashes$_POST['Locations']))); $Name = htmlspclchars(Trim(stripslashes($_POST['Name']))); $Phone = htmlspclchars(Trim(stripslashes($_POST['Phone']))); $Email = htmlspclchars(Trim(stripslashes($_POST['Email']))); $Message = htmlspclchars(Trim(stripslashes($_POST['Message']))); // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Location: "; $Body .= $locations; $Body .= "\n"; $Body .= "Request: "; $Body .= $Request; $Body .= "\n"; ?> Now prepare the email and mail it, let me see when you are all done. Be sure to check your scripts for consitancey. Ex $location != $locations != $Location != $Locations ... Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876556 Share on other sites More sharing options...
prettikittie Posted July 16, 2009 Author Share Posted July 16, 2009 Thanks WolfRage, But I'm getting an error - line 5, which is: $locations= htmlspclchars(Trim(stripslashes$_POST['Locations']))); I have to admit this wasn't as easy as I thought it would be! Thank you again for your time, I appreciate it ` Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876569 Share on other sites More sharing options...
WolfRage Posted July 16, 2009 Share Posted July 16, 2009 Sorry my misspelling of the function, always trying to shortcut. htmlspclchars should be htmlspecialchars Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876572 Share on other sites More sharing options...
prettikittie Posted July 16, 2009 Author Share Posted July 16, 2009 Sorry WolfRage ... still getting the empty location when the forms submitted ... I changed this just a little - added the ')' after stripslashes. The ntire code, as maybe I'm missing something?! I've also the tiny bit of php you'd suggested earlier placed just above the Locations section of the form. <?php $EmailFrom = "$Name"; $EmailTo = "xxx"; $Subject = "xxx"; $locations= htmlspecialchars(Trim(stripslashes($_POST['Locations']))); $Name = htmlspecialchars(Trim(stripslashes($_POST['Name']))); $Phone = htmlspecialchars(Trim(stripslashes($_POST['Phone']))); $Email = htmlspecialchars(Trim(stripslashes($_POST['Email']))); $Message = htmlspecialchars(Trim(stripslashes($_POST['Message']))); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Location: "; $Body .= $Location; $Body .= "\n"; $Body .= "Request: "; $Body .= $Request; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876602 Share on other sites More sharing options...
prettikittie Posted July 16, 2009 Author Share Posted July 16, 2009 I got it! Thank you so much ... the little tidbit you gave me about actually checking consistency? I left the s off of location ... Thanks again for your help. Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876616 Share on other sites More sharing options...
WolfRage Posted July 16, 2009 Share Posted July 16, 2009 No problem, glad I could help. Mark solved, thanks! Link to comment https://forums.phpfreaks.com/topic/166217-solved-drop-down-in-form-isnt-working-properly/#findComment-876620 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.