I have created a script which validates all sorts of information inputted via a HTML form. The only problem I have is with the checkboxes. I need to ensure that only 2 checkboxes out of the 5 are selected. To do this I have given each checkbox a value of 1 therefore by adding all the checkboxes values, if they are equal to one then the form is valid. Below is the checkbox part of my code
$valuesa = param('option1');
$valuesb = param('option2');
$valuesc = param('option3');
$valuesd = param('option4');
$valuese = param('option5');
$valuescalc = $valuesa + $valuesb + $valuesc + $valuesd + $valuese;
if ($valuescalc eq '2') {
#PASS
$one = 'aa';
}
#FAIL
else {
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P><b>Error 1 - $valuescalc (Choose 2 options)</b></font>";
The problem I have is that the code seems to work, and I can display that i.e. if I have 3 checkboxes ticked then $valuecalc is equal to 3. However, if I select 2 checkboxes and try to validate, I get an Error 500.
If you would like to see the form in action, here is the web address:
Thanks for all your help!
$valuesa = param('option1');
$valuesb = param('option2');
$valuesc = param('option3');
$valuesd = param('option4');
$valuese = param('option5');
$valuescalc = $valuesa + $valuesb + $valuesc + $valuesd + $valuese;
if ($valuescalc eq '2') {
#PASS
$one = 'aa';
}
#FAIL
else {
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P><b>Error 1 - $valuescalc (Choose 2 options)</b></font>";
The problem I have is that the code seems to work, and I can display that i.e. if I have 3 checkboxes ticked then $valuecalc is equal to 3. However, if I select 2 checkboxes and try to validate, I get an Error 500.
If you would like to see the form in action, here is the web address:
Thanks for all your help!