Hi,
I'm trying to write a function to validate forms with checkboxes (first time I've tried to write a function).
Everything seems ok with my code but I'm getting an error I don't understand or can find resources on.
If I press submit with no checkbox checked I get the following error: Warning: Invalid argument supplied for foreach()
Can anyone point out the issue? I'm not brilliantly confident with the posted variables but the foreach statement works in others contexts.
Thanks in advance. I hope the posting of the code doesn't seem presumptuous..
// If the RequestMethod is POST, then the form has been submitted
if ($_SERVER['REQUEST_METHOD']=='POST')
{
//for every element of the choice array bring back the array index and element value
foreach ($choice As $array_index => $flag)
{
// if the elements value is equal to 'on' i.e. the checkbox is checked
if ($flag=='on')
{
$checked_count++;
// Validate form, make sure the Customer Number is set and not empty
if ((isset($_POST[member_no][1])) && (!empty($_POST[member_no][1])))
{
//run insert into d/b program
header("Location: insert2.php");
exit();
}
else
{
// If input field is blank print a message
echo "<b>You must not leave member blank</b>";
}
} // end if flag==on
} // end foreach
if ($checked_count < 1)
{
echo "<b>You have to check at least one box</b>";
}
} // end if REQUEST_METHOD==POST