I have a form with several input methods. I pass that data to a perl script to process print out text based on the data input. I am having a problem with the values of a checkbox group. (checkboxes all with the same name)
<td>Profiles: </td>
<td><input type=\"checkbox\" value=\"oneconnect\" name=\profile[]\">OneConnect <br />
<input type=\"checkbox\" value=\"http\" name=\profile[]\">HTTP <br />
<input type=\"checkbox\" value=\"xforwardedfor\" name=\profile[]\">Xforwarded-for</td>
</tr>
</table>
The action sends this data to a perl script for processing.
read (STDIN, $FormData, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $FormData);
print Dumper($FormData);
foreach my $pair (@pairs) {
# Separate the name and value:
($name, $value) = split(/=/, $pair);
# Convert + signs to spaces:
$value =~ tr/+/ /;
# Convert hex pairs (%HH) to ASCII characters:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Store values in a hash called %FORM:
$FORM{$name} = $value;
}
I can then print most of the data the with:
print "$FORM{'vsip1'} $FORM{'vsport1'} <br />\n";
However, I cannot access the name “profile” from the checkboxes with the same print command. I do see the “profile” values when I “dump” the data.
print dumper output shows (&%5Cprofile%5B0%5D%22=oneconnect&%5Cprofile%5B1%5D%22=http&SubmitForm) Is this a hash of a hash? and how can I access these values in perl.
Thank you for any suggestions you can provide.
You should use CGI or CGI::Simple so you don’t have to worry about such matters.
See param.