Coding Thread, drop down list in a html webform and php in Coding and Web Development; Hi all i want to create a web form with a drop down list and have and have it sent ...
-
4th March 2008, 11:07 AM #1
- Rep Power
- 12
drop down list in a html webform and php
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
-
-
IDG Tech News
-
4th March 2008, 11:19 AM #2 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
-
-
4th March 2008, 02:01 PM #3 Might be worth posting your code so a bit of debugging can be done
-
-
4th March 2008, 02:09 PM #4 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?
-
-
4th March 2008, 04:29 PM #5
- Rep Power
- 12
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@email.com";
if ($_POST['envoi']) {
// E-mail headers:
$headers ="MIME-Version: 1.0 \n";
$headers .="From: website<email@email.com>\n";
$headers .="Content-Type: text/html; charset=iso-8859-1 \n";
$subject = "Enqu iryFrom website";
$header_part = "<html><head>
<meta http-equiv=Content-Type content=text/html; charset=iso-8859-1>
</head>
<body bgcolor=#FFFFFF>";
for ($a=1; $a<= $_POST['text_field_number']; $a++) {
$text_fields_part .= "<font face='Verdana' size='2' color='#003366'>" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . "</font><br>";
}
if ($_POST['email_field_number'] != 0) {
$email_field_part = "<font face='Verdana' size='2' color='#003366'>" . $_POST['email_title'] . " = " . $_POST['email_field'] . "</font><br>";
}
if ($_POST['textarea_number'] != 0) {
$text_area_field = "<font face='Verdana' size='2' color='#003366'>" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . "</font><br>";
$text_area_field = stripslashes($text_area_field);
}
$end = "</body></html>";
$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
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">function checkSelection() {} // End of function
</script></head>
<body><form name="mail_form" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="return checkSelection()">
<div align="center"></div>
<p align="center">
<table width="566" border="0" align="center">
<p align="center">
</p><tr>
<td><font face="Verdana" size="2">How many Beds</font></td>
<td><select id= "people" name="people" size="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="3">4</option>
<option value="3">5</option>
</select> </td>
</tr><tr>
<td><font face="Verdana" size="2">How many large Boxes</font></td>
<td><input name="field2" type="text"></td>
</tr><tr>
<td><font face="Verdana" size="2">How many wardrobes</font></td>
<td><input name="field3" type="text"></td>
</tr><tr>
<td><font face="Verdana" size="2">How many pianos</font></td>
<td><input name="field4" type="text"></td>
</tr><tr>
<td><font face="Verdana" size="2">How many small boxes</font></td>
<td><input name="field5" type="text"></td>
</tr><tr>
<td width><font face="Verdana" size="2">Email Address</font></td>
<td width><input name="email_field" type="text"></td>
</tr><tr>
<td valign="top"><font face="Verdana" size="2">Any other info here please</font></td>
<td><textarea name="textarea_field" cols="50" rows="10"></textarea></td>
</tr><tr>
<td valign="top"><input name="text_field_number" type="hidden" id="text_field_number" value="5">
<input name="textarea_number" type="hidden" value="1">
<input name="email_field_number" type="hidden" value="1">
<input name="field_title1" type="hidden" value="How many Beds"><input name="field_title2" type="hidden" value="How many large Boxes"><input name="field_title3" type="hidden" value="How many wardrobes"><input name="field_title4" type="hidden" value="How many pianos"><input name="field_title5" type="hidden" value="How many small boxes"><input name="email_title" type="hidden" value="Email Address"><input name="textarea_title" type="hidden" value="Any other info here please"></td>
<td><div align="center">
<input type="reset" name="Reset" value="Clear">
<input type="submit" name="envoi" value="Submit">
</div></td>
</tr>
</table>
<div align="center"></div>
</form>
</body>
</html>
//end code
-
-
4th March 2008, 04:38 PM #6 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.
-
-
4th March 2008, 04:39 PM #7 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
-
-
4th March 2008, 04:55 PM #8
- Rep Power
- 12
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?
-
-
4th March 2008, 04:57 PM #9 
Originally Posted by
Ryan
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!
-
-
4th March 2008, 05:00 PM #10 After:
if ($_POST['textarea_number'] != 0) {
$text_area_field = "<font face='Verdana' size='2' color='#003366'>" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . "</font><br>";
$text_area_field = stripslashes($text_area_field);
}
Put something like:
$text_area_field = $text_area_field." <br>People:".stripslashes($_POST['people'])."<br>";
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!)
Last edited by Shane; 4th March 2008 at 05:59 PM.
-
-
5th March 2008, 08:58 AM #11
- Rep Power
- 12
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.
-
-
5th March 2008, 09:10 AM #12 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'
-
-
5th March 2008, 09:53 AM #13 //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@email.com";
if ($_POST['envoi']) {
// E-mail headers:
$headers ="MIME-Version: 1.0 \n";
$headers .="From: website<email@email.com>\n";
$headers .="Content-Type: text/html; charset=iso-8859-1 \n";
$subject = "Enqu iryFrom website";
$header_part = "<html><head>
<meta http-equiv=Content-Type content=text/html; charset=iso-8859-1>
</head>
<body bgcolor=#FFFFFF>";
for ($a=1; $a<= $_POST['text_field_number']; $a++) {
$text_fields_part .= "<font face='Verdana' size='2' color='#003366'>" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . "</font><br>";
}
if ($_POST['email_field_number'] != 0) {
$email_field_part = "<font face='Verdana' size='2' color='#003366'>" . $_POST['email_title'] . " = " . $_POST['email_field'] . "</font><br>";
}
if ($_POST['textarea_number'] != 0) {
$text_area_field = "<font face='Verdana' size='2' color='#003366'>" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . "</font><br>";
$text_area_field = stripslashes($text_area_field);
}
$text_area_field = $text_area_field."<br>People:".stripslashes($_POST['people'])."<br>";
$end = "</body></html>";
$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
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">function checkSelection() {} // End of function
</script></head>
<body><form name="mail_form" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="return checkSelection()">
<div align="center"></div>
<p align="center">
<table width="566" border="0" align="center">
<p align="center">
</p><tr>
<td><font face="Verdana" size="2">How many Beds</font></td>
<td><select id= "people" name="people" size="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="3">4</option>
<option value="3">5</option>
</select> </td>
</tr><tr>
<td><font face="Verdana" size="2">How many large Boxes</font></td>
<td><input name="field2" type="text"></td>
</tr><tr>
<td><font face="Verdana" size="2">How many wardrobes</font></td>
<td><input name="field3" type="text"></td>
</tr><tr>
<td><font face="Verdana" size="2">How many pianos</font></td>
<td><input name="field4" type="text"></td>
</tr><tr>
<td><font face="Verdana" size="2">How many small boxes</font></td>
<td><input name="field5" type="text"></td>
</tr><tr>
<td width><font face="Verdana" size="2">Email Address</font></td>
<td width><input name="email_field" type="text"></td>
</tr><tr>
<td valign="top"><font face="Verdana" size="2">Any other info here please</font></td>
<td><textarea name="textarea_field" cols="50" rows="10"></textarea></td>
</tr><tr>
<td valign="top"><input name="text_field_number" type="hidden" id="text_field_number" value="5">
<input name="textarea_number" type="hidden" value="1">
<input name="email_field_number" type="hidden" value="1">
<input name="field_title1" type="hidden" value="How many Beds"><input name="field_title2" type="hidden" value="How many large Boxes"><input name="field_title3" type="hidden" value="How many wardrobes"><input name="field_title4" type="hidden" value="How many pianos"><input name="field_title5" type="hidden" value="How many small boxes"><input name="email_title" type="hidden" value="Email Address"><input name="textarea_title" type="hidden" value="Any other info here please"></td>
<td><div align="center">
<input type="reset" name="Reset" value="Clear">
<input type="submit" name="envoi" value="Submit">
</div></td>
</tr>
</table>
<div align="center"></div>
</form>
</body>
</html>
//end code
-
-
5th March 2008, 09:55 AM #14 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)
Last edited by Shane; 5th March 2008 at 10:20 AM.
-
-
5th March 2008, 12:25 PM #15
- Rep Power
- 12
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 = a@bc.com
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
-
SHARE:
Similar Threads
-
By HodgeHi in forum Web Development
Replies: 2
Last Post: 24th November 2007, 03:52 PM
-
By FN-GM in forum IT News
Replies: 6
Last Post: 1st August 2007, 08:21 PM
-
By Quackers in forum Coding
Replies: 2
Last Post: 5th June 2007, 08:03 AM
-
By Kyle in forum General Chat
Replies: 22
Last Post: 17th February 2007, 03:57 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules