Dr_Weed
December 11, 2013, 11:30am
1
So I want to add dropdown item with 4 option and I want that option to be sent back to my email when you user selects it.
I searched on the Internet, but I couldnt find that. Here are my files if someone can help me.
Thanks
PHP file
JavaScript file
ralphm
December 11, 2013, 1:11pm
2
Hi Dr W.
The first thing you need to do is set up a select list in your HTML form, something like this:
<label for="something">Some List</label>
<select id="something" name="something">
<option value="First Choice">First Choice</option>
<option value="Second Choice">Second Choice</option>
<option value="Third Choice">Third Choice</option>
<option value="Fourth Choice">Fourth Choice</option>
</select>
Set up your select list as you’d like it, and then we can help with processing it.
Dr_Weed
December 11, 2013, 8:10pm
3
Yes I have done this before.
<label name="dropdown">Reason</label>
<select id="something" name="something">
<option value="First Choice">First Choice</option>
<option value="Second Choice">Second Choice</option>
<option value="Third Choice">Third Choice</option>
Whats next?
ralphm
December 11, 2013, 10:55pm
4
Your alterations to the form have messed it up, so it’s important to get that right first. The name attribute on the label needs to match the id on the select element.
<label for="dropdown">Some List</label>
<select id="dropdown" name="dropdown">
<option value="First Choice">First Choice</option>
<option value="Second Choice">Second Choice</option>
<option value="Third Choice">Third Choice</option>
<option value="Fourth Choice">Fourth Choice</option>
</select>
Anyhow, the next step would be something like this in your PHP:
if (isset($_POST["dropdown"])) {
$dropdown = $_POST["dropdown"];
}
or this, to match your pattern:
if(isset($_POST['dropdown']!='nope')){
$messageBody .= '<p>Dropdown choice: ' . $_POST["dropdown"] . '</p>' . "\
";
$messageBody .= '<br>' . "\
";
}
Dr_Weed
December 12, 2013, 3:04pm
5
Your alterations to the form have messed it up, so it’s important to get that right first. The name attribute on the label needs to match the id on the select element.
<label for="dropdown">Some List</label>
<select id="dropdown" name="dropdown">
<option value="First Choice">First Choice</option>
<option value="Second Choice">Second Choice</option>
<option value="Third Choice">Third Choice</option>
<option value="Fourth Choice">Fourth Choice</option>
</select>
Anyhow, the next step would be something like this in your PHP:
if (isset($_POST["dropdown"])) {
$dropdown = $_POST["dropdown"];
}
or this, to match your pattern:
if(isset($_POST['dropdown'])){
$messageBody .= '<p>Dropdown choice: ' . $_POST["dropdown"] . '</p>' . "\
";
$messageBody .= '<br>' . "\
";
}
Now it doesnt want to submit it, I mean, submit button doesnt work. Maybe there is something that needs to be added inside js file. I posted it in first post.
Thats why its a little bit complicated for me, it uses js.
ralphm
December 13, 2013, 2:24am
6
Probably, or you could just delete the JS, as the form (if it’s written properly) should work without JS. The JS is over my head, though, so if you really want it, we could move this to the JS forum. As a test, it would be worth checking if it works without JS. (Hopefully the HTML doesn’t have inline event handlers.)
Dr_Weed
December 13, 2013, 8:03am
7
But it doesnt really work, because it says “Field is required” and it wont send the message because of it
ralphm
December 13, 2013, 1:14pm
8
I had a typo in my post that may have caused an issue. What if you use this?
if(isset($_POST['dropdown'])){
$messageBody .= '<p>Dropdown choice: ' . $_POST["dropdown"] . '</p>' . "\
";
$messageBody .= '<br>' . "\
";
}