After toying around with this for awhile I came up with this:
In the HTML form use an array (here, test[])for the value for each of a group of checkboxes:
<INPUT TYPE="checkbox" NAME="test[]" VALUE="1">1
<INPUT TYPE="checkbox" NAME="test[]" VALUE="2">2
In the processing PHP file, check all the HTTP Post variables and find out for each, if it's an array; If so, it's a checkbox - since I use the array 'test[]' in my form above.
For each element of the array, see if there's a value - once we find one then we know the user has checked at least one box and set $fnd_error to 0 (zero).
In my code, I handle errors by adding the field to the errors[] array, if there's a non-empty value, we add it to the values[] array:
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
Handle arrays (checkboxes)
if (is_array($val)) {
$fnd_error = 1;
while (list ($array_k, $array_v) = each ($val)) {
if ($array_v != "") {
$fnd_error = 0;
}
}
if ($fnd_error == 1) {
$errors[$a] = $key;
$a = $a + 1;
} else {
$values[$key] = $val;
$b = $b + 1;
}
Handle non-arrays (everything else)
} else {
non-array error-checking code here
}
Anyhow, this might be more than you're looking for, but I felt a full example will help you deal with the next natural question I had: how to deal with verifying checkbox variables!!
Regards,
Kevin