Can anyone recommend a way to get POST data from a SELECT form dropdown? I have been using PHP to access a particular value from a set of form POST data by doing something like:
$value2 = $_POST[‘value2’]
That works quite nicely to extract the value that I need when the form input box has only a single value . I am now trying to do the same thing when using a select drop down form with multiple options and the same method no longer works. I reference the select name, but no luck. Any suggestions would be appreciated.
<tr> <td class=“form_c”>Salutation </td><td class=“form_c”></td>
<td class=“form_c”>
<select input type =“text” name = “salutation” maxlength = “6” value=“<?php echo $_SESSION[‘salutation’] ?>” ><option></option><option>Mr</option>
<option>Mrs</option>
<option>Ms</option>
<option>Miss</option>
<option>Dr</option>
</select></td>
<td class=“form_c”></td><td class=“form_c”><small>Tips to help fill in the form</small></td></tr>
with this situated on the page you process to…
$salutation = $_POST[‘salutation’];
$_SESSION[‘salutation’] = $salutation;
then I validate the entry…if it is is not valid when I send them back the data is still held, if valid the process move on.
The key thing is the session variable( the selection) held in the session array. Try using this so you can see what is held or not…
Thank you Defiance, that seems to work. The key difference between grabbing something from an input box as opposed to select options seems to be the single quotes.
$_POST[‘Subject’] … works when there is one option coming from an input box
$_POST[Subject] … works when there is one option coming from a multiple choice SELECT dropdown
You use arrays when you need to get values from multiple Select statements for the same entity.
For example, on my current script I have multiple artists per item and on the add item page, the user enters the number of artists they want the item to have and instead of doing <select name=“Artist1”></select><select name=“Artist2”>… <select name=“Artistn”> I simply have <select name=“artist”> for all of them. The same applies for any dynamically created form… it’s much easier just to use an array.
In this case, you only have one select so just give it a name and give each option a value and it will work. $_POST[‘Subject’] is the same as $_POST[Subject] in your case and both will work.