#!/usr/bin/perl
####################### example2.cgi
############ Example of perl to check for unchecked radio buttons
print "Content-type:text/html\n\n";
#read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$buffer = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# Output for demonstration purposes:
#print "$FORM{'rbphplike'}
";
# Initialize the Radio Button Array
%rbuttons = ("height" => "Please answer height question (1a)",
"sex" => "Please answer sex question (1b)",
"eyecolor" => "Please answer eye color question (1c)",
"eyecolors" => "Please answer eye color question (1c)",
"skincolor" => "Please answer skin color question (1d)",
"skincolors" => "Please answer color of skin desired question (1d)",
"art" => "Please answer artistic ability question (1e)",
"math" => "Please answer math ability question (1f)",
"athletic" => "Please answer athletic question (1g)",
"temperament" => "Please answer temperament question (1h)",
"handedness" => "Please answer handedness question (1i)",
"handed" => "Please answer handed question (1i)",
"life" => "Please answer life question (1j)",
"aids" => "Please answer aids question (1k)",
"cancer" => "Please answer cancer question (1l)",
"downs" => "Please answer downs question (1m)",
"vision" => "Please answer vision question (1n)",
"hearing" => "Please answer hearing question (1o)",
"speech" => "Please answer speech question (1p)",
"abortion" => "Please answer abortion question (3)",
"expenses" => "Please answer expenses question (5a)",
"percent" => "Please answer percent question (5b)",
"usex" => "Please answer sex question (1)",
# "uethnic" => "Please answer ethnic question (2)",
"uheightrange" => "Please answer height range question (4b)",
"uchildren" => "Please answer children question (5)",
"uhanded" => "Please answer handed question (6)",
"uart" => "Please answer art question (8)",
"umath" => "Please answer math question (9)",
"uathletic" => "Please answer athletic question (10)");
# Output for demonstration purposes:
#print "$FORM{'ckphpknow'}
";
# Initialize the Checkboxes Array
%ckboxes = ( ### no check needed for the commented out checkboxes
#"nokidspoverty" => "Please select answer(s) for poverty selection (4a)",
#"nokidshomeless" => "Please select answer(s) for homeless selection (4a)",
#"nokidsunstable" => "Please select answer(s) for unstable selection (4a)",
#"nokidsdownschild" => "Please select an answer for downs selection (4a)",
#"nokidscriminals" => "Please select an answer for crimainals selection (4a)",
#"nokidsmedicalcondition" => "Please select an answer for medical condition selection (4a)",
"ethnicafrican" => "Please select an answer for african selection (2)",
"ethnicamericanindian" => "Please select an answer for american indian selection (2)",
"ethnicasian" => "Please select an answer for asian selection (2)",
"ethniccaucasian" => "Please select an answer for caucasian selection (2)",
"ethnichispanic" => "Please select an answer for hispanic selection (2)");
#### Initial check for errors in radio buttons
$flagradio = 1; # initialize radio flag to true
$flagcheck = 1; # initialize check falg to true
$flagtext = 1; # initialize text flag to true
#### Initial test for text boxes
if ($FORM{'nokidstext'} eq "" or
$FORM{'childchars'} eq "" or
$FORM{'age'} eq "" or
$FORM{'uheightfeet'} eq "" or
$FORM{'uheightinches'} eq "" or
$FORM{'ueyecolor'} eq "" or
$FORM{'religion'} eq "" or
$FORM{'major'} eq ""){ $flagtext = 0;}
foreach $RbKey (keys %rbuttons) {
if (!$FORM{$RbKey}){
$flagradio=0; #case were errors are found
}
}
#### Initial check for errors in check boxes
foreach $RbKey (keys %ckboxes) {
if (!$FORM{$RbKey}){
$check=($check + 1); #number of check boxes checked, need at least one
}
}
#### Check to see of check boxes have at least one box checked
if( $check > 4 ){
$flagcheck = 0;
}
#### Begining of web page
if ( $flagradio == 0 || $flagcheck == 0 || $flagtext == 0){ #some errors found
print "