PDA

View Full Version : PHP - Sending dropdown list items in email



fanderson
November 30th, 2007, 09:32 AM
Hi,

I am working on sending the contents of an html form via email. I have the standard fields such as name and address that come through fine using '{$_POST['name']}' etc., however, I have a couple of list items that show as dropdowns in the form.

I checked php.net/mail but it didn't have any clues, so I would really appreciate some guidance on how to the selected value from something like this to show up in the email:

<label for="problem">Problem Type:</label>
<select>
<option value="selected" selected="selected">-- Select --</option>
<option value="plumbing">Plumbing</option>
<option value="electrical">Electrical</option>
<option value="hvac">HVAC</option>
<option value="roofing">Roofing</option>
<option value="grounds">Grounds</option>
<option value="parking">Parking</option>
<option value="other">Other</option>
</select>

Thanks in advance for the help.

borrob
November 30th, 2007, 10:04 AM
you have a form wherein this select resides so do the following:

change <select> in
<select name='problem_select'>

you can now acces the value through
$_POST['problem_select']

fanderson
November 30th, 2007, 10:30 AM
Thanks for the reply. Since this is a variable and could change with each submission of the form, how does that work? Please err on the side of explaining too much.

negativecreep
November 30th, 2007, 11:35 AM
As stated above, your select box does not have a name. So once you name is something like "problem_select". You can access the value of it through your post. So whatever they select the value of that variable will correspond with the value of the option they picked in the select box. I.e., If they select Plumbing, the value of $_POST['problem_select'] = "plumbing".

Just like if you have a textbox called "FirstName", and when you call $_POST['FirstName']. You would get the value of whatever they typed in. In this case the value is predetermined by you by what they select.

I hope that kind helps you understand it...

fanderson
November 30th, 2007, 01:42 PM
Many thanks to borrob and negativecreep for their kind and effective assistance. It works as I had hoped.