Forum Moderators: coopster
I want to create a form that will mail different people depending on the selection using the <option> values.
So far, i've put the options into arrays like so:
<select name=to[]>
<option></option>
<option></option>
</select>
Is this correct?
I think the problem i'm having is how to recall the specific option in the if statement:
using if($_POST['to[0]']) doesn't work.
Can somebody help please? Much appreciated =)
<select name=to>
<option></option>
<option></option>
<option></option>
</select>
<?php
$tomail = $_POST['to'];
switch ($tomail) {
case 0:
mail(...);
echo ...;
break;
case 1:
mail(...);
echo ...;
break;
?>
It still doesn't work - does case 0 even though the second option is selected. =(
What do i do?
testform.php
<?php
if ($_POST['to'] == "none") echo "<p>please select someone to send to";
$tomail = $_POST['to'];
switch ($tomail) {
case 1:
echo "<p>bob";
break;
case 2:
echo "<p>doug";
break;
case 3:
echo "<p>take off eh";
break;
default:
break;
}
?>
<p><form method="post" action="testform.php">
<select name="to">
<option value="none">select please</option>
<option value="1">bob</option>
<option value="2">doug</option>
<option value="3">mckenzie</option>
</select>
<input type="submit" value="go for it">
</form>
I would assign the value in the switch and call the mail function at the end of the script but that is just a preference thing. It would mean you only have to manage a single function call instead of many calls to the same thing.