Uraken Posted March 4, 2008 Posted March 4, 2008 Hi all i want to create a web form with a drop down list and have and have it sent to my email. I have created standard html form and the php file that sends it to my email which works ok, for all the text boxex in the form but when i add a drop down list menu to the form the results don't come through as there is no coresponding php code in the php file and i don't how to do this, can anyone help please? thanks in advance
Jona Posted March 4, 2008 Posted March 4, 2008 This might help: http://www.w3schools.com/tags/tag_option.asp If you set an id / name in the option tag you should be able to read the value it's assigned just like any other field. Cheers Jona 1
cl0n3 Posted March 4, 2008 Posted March 4, 2008 Might be worth posting your code so a bit of debugging can be done
Ryan Posted March 4, 2008 Posted March 4, 2008 I've done something like this recently for a couple of little projects. I'll post again when i get home. Where's the contents of your list coming from? Database/file or hand-coded?
Uraken Posted March 4, 2008 Author Posted March 4, 2008 thanks for the replys all the code is enclosed i save it all as a php file upload and most works just not the drop down bit: //begin code <?php // Only show error messages, not the warnings... ini_set("error_reporting", "E_ALL & ~E_NOTICE"); // E-mail address to which the form will be sent... $form_email = "[email protected]"; if ($_POST['envoi']) { // E-mail headers: $headers ="MIME-Version: 1.0 \n"; $headers .="From: website\n"; $headers .="Content-Type: text/html; charset=iso-8859-1 \n"; $subject = "Enqu iryFrom website"; $header_part = " "; for ($a=1; $a<= $_POST['text_field_number']; $a++) { $text_fields_part .= "" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . ""; } if ($_POST['email_field_number'] != 0) { $email_field_part = "" . $_POST['email_title'] . " = " . $_POST['email_field'] . ""; } if ($_POST['textarea_number'] != 0) { $text_area_field = "" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . ""; $text_area_field = stripslashes($text_area_field); } $end = ""; $output = $header_part . $text_fields_part . $email_field_part . $text_area_field . $end; // Send the e-mail if (@!mail($form_email,$subject,$output,$headers)) { echo("Cannot send the form"); } else { // Closing if !mail... // Redirect to the thank you page header("Location:thankyou.html"); exit(); } // Fin du else } // Closing if edit ?> Untitled Document How many Beds 1 2 3 4 5 How many large Boxes How many wardrobes How many pianos How many small boxes Email Address Any other info here please //end code
cl0n3 Posted March 4, 2008 Posted March 4, 2008 In the bit where you are fetching the submitted variables (using $_POST) I don't see where you are fetching the 'people' variable which would be filled with the value from the drop down box. This could be why you do not get this value in the email.
Ryan Posted March 4, 2008 Posted March 4, 2008 Yep, as Shane says, you need to be pulling that information back in. There's nothing being passed from the dropdown selection. And i won't mention the use of the deprecated FONT tag or the replication of code at this point
Uraken Posted March 4, 2008 Author Posted March 4, 2008 Hi chaps i'm not sure if i gave the impression i wrote this myself (god no, i wish i was that clever) so please assume very little coding knowledge and feel free to point out the errors, as well as guidance as to how to put them right. Can you show me the code i need to add please?
cl0n3 Posted March 4, 2008 Posted March 4, 2008 And i won't mention the use of the deprecated FONT tag or the replication of code at this point Damn another rule from Fight Club that I've failed!
cl0n3 Posted March 4, 2008 Posted March 4, 2008 (edited) After: if ($_POST['textarea_number'] != 0) { $text_area_field = "" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . ""; $text_area_field = stripslashes($text_area_field); } Put something like: $text_area_field = $text_area_field." People:".stripslashes($_POST['people']).""; But you may need to do more to sort out stopping people from adding naughty code etc (I am going over in my head the crudeness that I have used but I have to run now, sorry!) Edited March 4, 2008 by cl0n3
Uraken Posted March 5, 2008 Author Posted March 5, 2008 i tried that line of code shane it returns the all the text boxes but nothing for the drop down although it does now say the word people at the bottom of the email message now. I'm lost now and in above my head i think.
alan-d Posted March 5, 2008 Posted March 5, 2008 Not an answer to your question but I spotted this $subject = "Enqu iryFrom website"; move the space from between the 'u' and 'i' and put it after the 'y' 1
cl0n3 Posted March 5, 2008 Posted March 5, 2008 //begin code <?php // Only show error messages, not the warnings... ini_set("error_reporting", "E_ALL & ~E_NOTICE"); // E-mail address to which the form will be sent... $form_email = "[email protected]"; if ($_POST['envoi']) { // E-mail headers: $headers ="MIME-Version: 1.0 \n"; $headers .="From: website\n"; $headers .="Content-Type: text/html; charset=iso-8859-1 \n"; $subject = "Enqu iryFrom website"; $header_part = " "; for ($a=1; $a<= $_POST['text_field_number']; $a++) { $text_fields_part .= "" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . ""; } if ($_POST['email_field_number'] != 0) { $email_field_part = "" . $_POST['email_title'] . " = " . $_POST['email_field'] . ""; } if ($_POST['textarea_number'] != 0) { $text_area_field = "" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . ""; $text_area_field = stripslashes($text_area_field); } $text_area_field = $text_area_field."People:".stripslashes($_POST['people']).""; $end = ""; $output = $header_part . $text_fields_part . $email_field_part . $text_area_field . $end; // Send the e-mail if (@!mail($form_email,$subject,$output,$headers)) { echo("Cannot send the form"); } else { // Closing if !mail... // Redirect to the thank you page header("Location:thankyou.html"); exit(); } // Fin du else } // Closing if edit ?> Untitled Document How many Beds 1 2 3 4 5 How many large Boxes How many wardrobes How many pianos How many small boxes Email Address Any other info here please //end code
cl0n3 Posted March 5, 2008 Posted March 5, 2008 (edited) If you can try that out and post back here with any errors (Sorry I dont have access to the Apache server at the moment so can't test it out). Cheers (May need to remove the line: ini_set("error_reporting", "E_ALL & ~E_NOTICE"); to see the any errors) Edited March 5, 2008 by cl0n3 1
Uraken Posted March 5, 2008 Author Posted March 5, 2008 hi shane thanks that works now although it returns it at the bottom like this: How many Beds = How many large Boxes = 3 How many wardrobes = 3 How many pianos = 3 How many small boxes = 3 Email Address = [email protected] Any other info here please = fsgdf How many beds:2 p.s if i have more than one drop down can i assume i repeat the syntax with the new select id? thanks again
cl0n3 Posted March 5, 2008 Posted March 5, 2008 (edited) hi shane thanks that works now although it returns it at the bottom like this: How many Beds = How many large Boxes = 3 How many wardrobes = 3 How many pianos = 3 How many small boxes = 3 Email Address = [email protected] Any other info here please = fsgdf How many beds:2 p.s if i have more than one drop down can i assume i repeat the syntax with the new select id? thanks again You will also need a new name variable for the new select element (So in the first drop down box the name is 'people' this will have to be different in a new one as this is what the $_POST uses) So you would like the 'How many beds' information at the top of the email yeah? Try this: //begin code <?php // Only show error messages, not the warnings... ini_set("error_reporting", "E_ALL & ~E_NOTICE"); // E-mail address to which the form will be sent... $form_email = "[email protected]"; if ($_POST['envoi']) { // E-mail headers: $headers ="MIME-Version: 1.0 \n"; $headers .="From: website\n"; $headers .="Content-Type: text/html; charset=iso-8859-1 \n"; $subject = "Enqu iryFrom website"; $header_part = " "; $text_fields_part = "How many bed:".stripslashes($_POST['people']).""; for ($a=1; $a<= $_POST['text_field_number']; $a++) { $text_fields_part .= "" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . ""; } if ($_POST['email_field_number'] != 0) { $email_field_part = "" . $_POST['email_title'] . " = " . $_POST['email_field'] . ""; } if ($_POST['textarea_number'] != 0) { $text_area_field = "" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . ""; $text_area_field = stripslashes($text_area_field); } $end = ""; $output = $header_part . $text_fields_part . $email_field_part . $text_area_field . $end; // Send the e-mail if (@!mail($form_email,$subject,$output,$headers)) { echo("Cannot send the form"); } else { // Closing if !mail... // Redirect to the thank you page header("Location:thankyou.html"); exit(); } // Fin du else } // Closing if edit ?> Untitled Document How many Beds 1 2 3 4 5 How many large Boxes How many wardrobes How many pianos How many small boxes Email Address Any other info here please //end code Again sorry I can't test it (sorry I keep on editing this post, keep seeing things that I need to change) Edited March 5, 2008 by cl0n3
Uraken Posted March 5, 2008 Author Posted March 5, 2008 thanks for that shane i understand it now. The last code did not work so i reverted back i will have to make do with it where it is thanks again for your help.
cl0n3 Posted March 5, 2008 Posted March 5, 2008 thanks for that shane i understand it now. The last code did not work so i reverted back i will have to make do with it where it is thanks again for your help. No worries
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now