Error checking those evil checkboxes
Posted: Sat May 11, 2002 3:39 pm
I have the following code:
I need someway to check that at least one of the checkboxes is checked.
Radio buttons are easy as they are all the same name, thus i use:
So with this i can have this:
(S1Q1 being the name of the radio buttons)
Which would see if a value was passed. But in this situation the check boxes all have their own name thus a simple check like this cannot be done.
I need a way to check that at least one of the check boxes have been checked.
Any suggestion..... I'm not sure where to begin.....i'm just a baby when it comes to PHP.
Thanks for your help in advance.
Code: Select all
I don't have a computer/console
<input type="checkbox" name="S1Q3_1" value="0"><br>
Playing interactive games is unsociable
<input type="checkbox" name="S1Q3_2" value="0"><br>
Playing interactive games is boring
<input type="checkbox" name="S1Q3_3" value="0"><br>
Playing interactive games is geeky
<input type="checkbox" name="S1Q3_4" value="0"><br>
They're expensive
<input type="checkbox" name="S1Q3_5" value="0"><br>
I have never had the opportunity
<input type="checkbox" name="S1Q3_6" value="0"><br>
I don't have the time
<input type="checkbox" name="S1Q3_7" value="0"><br>
Other
<input type="checkbox" name="S1Q3_8" value="0"><br>Radio buttons are easy as they are all the same name, thus i use:
Code: Select all
// check whether input is empty
function isEmpty($field, $msg)
{
$value = $this->_getValue($field);
if (trim($value) == "")
{
$this->_errorListї] = array("field" => $field, "value" => $value, "msg" => $msg);
return false;
}
else
{
return true;
}
}(S1Q1 being the name of the radio buttons)
Code: Select all
$fv->isEmpty("S1Q1", "You have not selected whether you play games or not");
if ($fv->isError())
{
$errors = $fv ->getErrorList();
echo "<br>The operation could not be preformed because one or more error(s) occu
rred.</br>";
echo "<ul>";
foreach ($errors as $e)
{
echo "<li>" . $eї'msg'];
}
echo "</ul>";
echo '<br>Please go <a href="#" onClick="history.go(-1)">Back</a> and try agai
n</br>';
}I need a way to check that at least one of the check boxes have been checked.
Any suggestion..... I'm not sure where to begin.....i'm just a baby when it comes to PHP.
Thanks for your help in advance.