I have a form that is populated based on a database. In particular I have a multiple pulldown menus like this:
echo "<td width=\"112\"><select name=\"temperature[$itemId]\">
<option value=\"0\">-- Select --</option>
<option value=\"Blood-Rare\">Blood-Rare</option>
<option value=\"Medium Rare\">Medium-Rare</option>
<option value=\"Medium\">Medium</option>
<option value=\"Medium-Well\">Medium-Well</option>
<option value=\"Well Done\">Well Done</option>
</select></td>";
When the user submits the form the values are been stored in an array. How do I validate the form to ensure that the user selects something other than "-- Select --".
I have tried the following and do not understand why it does not work:
if ($_POST['_submit_check']) {
foreach($_POST['temperature'] as $key => $value){
if($value == 0)){
$error = "Please select temperature";
} else {
process_form();
}
}
I do not get any errors, the page just keeps refreshing when the form is submitted.
Any thoughts or tutorials on how to do form validation when arrays are used? I am totally confused about why this won't work.
Any help would be greatly appreciated.
Thanks!