I have a HTML form which is using a simple PHP mail()
script to send its contents to an email address. I have just implemented a drop down list:
Use this for your html form:
<select name="event">
<option value="event1">Event 1</option>
<option value="event2">Event 2</option>
<option value="event3">Event 3</option>
</select>
And use this on your php page that your form submits to:
$event = $_POST['event']
or
$event = $_GET['event']
Each option element does not get its own name, just a value.
Source: http://www.w3.org/TR/html401/interact/forms.html#h-17.6
Remove the name
attribute from your option elements:
<select name="event">
<option value="event1">Event 1</option>
<option value="event2">Event 2</option>
<option value="event3">Event 3</option>
</select>
And depending on the method (post
or get
) your form element is using, you should use either:
$event = $_POST["event"];
or
$event = $_GET["event"];
Don't forget to use htmlspecialchars() or mysqli_real_escape_string() if saving to a database or printing back to the user in addition to using mail().