Checkboxes with Perl CGI

cgi, checkbox, html, perl

Solution

You need to set the param() result into an array if you have multiple form elements with the same name.From CGI101:

my @colors = param('color');
foreach my $color (@colors) {
    print "You picked $color.<br>\n";
}

Problem

Sorry if my question is too simple, I am just starting out with CGI... So I have a bunch of checkboxes with the same name. Sample HTML: ``` <form action="/cgi-bin/checkbox.cgi" method="POST"> <input name="Loc_opt" value="Loc_1" type="checkbox">Option 1<br> <input name="Loc_opt" value="Loc_2" type="checkbox">Option 2<br> <input name="Loc_opt" value="Loc_3" type="checkbox">Option 3<br> <input type="submit" value="Submit"> </form> ``` I need to find out which of them are checked using Perl CGI. I have the following in checkbox.cgi: ``` print "Content-type:text/html\r\n\r\n"; local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }else { $buffer = $ENV{'QUERY_STRING'}; } # Split information into name/value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } ``` What should I do to now print, say, the values of the selected checkboxes?

Original source