Thanks for your quick response. I just tried using == and I still get an Error 500 when I select 2 checkboxes.
Bear in mind that there is code before and code after. I have just selected and pasted the relavent bits. I have also tried printing a statement if the code is valid rather than saying that $one = 'aa'.
Any other suggestions? How would you validate a group of 5 checkboxes to check if only 2 are checked?
Here is my full code if you wish to see, and you can obviously view the source code for the form at
if you wish
#! /usr/bin/perl
use strict;
use CGI ':standard';
############################################################
#######################
## Declare variables ##
#######################
####################
## Form variables ##
####################
my ($valuesa, $valuesb, $valuesc, $valuesd, $valuese);
my ($valuescalc);
my (@values2, $values3, $values4, $values5, $values6);
##########################
## Evaluation variables ##
##########################
my ($one, $two, $three, $four, $five, $six);
##########################################################
##########################################################
#####################
## Connect to form ##
#####################
$valuesa = param('option1');
$valuesb = param('option2');
$valuesc = param('option3');
$valuesd = param('option4');
$valuese = param('option5');
@values2 = param('menu1');
$values3 = param('text1');
$values4 = param('text2');
$values5 = param('text3');
$values6 = param('textbox1');
##########################################################
##########################################################
################################
## A) Checkboxes (2 selected) ##
################################
$valuescalc = $valuesa + $valuesb + $valuesc + $valuesd + $valuese;
if ($valuescalc == '2') {
$one = 'aa';
}
else {
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P><b>Error 1 - $valuescalc (Choose 2 options)</b></font>";
}
##########################################################
##########################################################
##########################
## B) Menu (1 selected) ##
##########################
if (param('menu1') eq '1') {
print "<font face=arial size=2><P><b>Error 2 - @values2 (Choose 1 option)</b></font>";
}
elsif ((@values2 eq '2') || (@values2 eq '3') || (@values2 eq '4') || (@values2 eq '5') || (@values2 eq '6')) {
$two = 'bb';
}
##########################################################
##########################################################
######################
## C) Text 1 (word) ##
######################
if ($values3 eq "") {
print "<font face=arial size=2><P><b>Error 3 - $values3 (Type text)</b></font>";
}
else {
$three = 'cc';
}
##########################################################
##########################################################
#######################
## D) Text 2 (email) ##
#######################
if (($values4 =~ /@/) && ($values4 =~ /./)) {
$four = 'dd';
}
else {
print "<font face=arial size=2><P><b>Error 4 - $values4 (Type an email address)</b></font>";
}
##########################################################
##########################################################
###########################
## E) Text 3 (telephone) ##
###########################
if ($values5 > 99999999999) {
print "<font face=arial size=2><P><b>Error 5 - $values5 (Type a telephone number)</b></font>";
}
elsif ($values5 =~ /\d\d\d\d\d\d\d\d\d\d\d/) {
$five = 'ee';
}
else {
print "<font face=arial size=2><P><b>Error 5 - $values5 (Type a telephone number)</b></font>";
}
##########################################################
##########################################################
#######################
## F) Textbox (word) ##
#######################
if ($values6 eq "") {
print "<font face=arial size=2><P><b>Error 6 - $values6 (Type text)</b></font>";
}
else {
$six = 'ff';
}
##########################################################
##########################################################
######################
## Final evaluation ##
######################
if (($one eq 'aa') && ($two eq 'bb') && ($three eq 'cc') && ($four eq 'dd') && ($five eq 'ee') && ($six eq 'ff')) {
print "<p><font face=arial size=2><P><font color=green><b>Form Completed Correctly</b></font>";
}
else {
print "<p><font face=arial size=2><P><font color=red><b>Form Completed Incorrectly</b></font>";
}
##########################################################
#########
## End ##
#########