I'm getting strange results from a subroutine that is passed a hash of values, one of which comes from a checkbox from an online form.
The relevant html and code are as follows:
What happens is this:# html # Note that if the user selects the checkbox, the value is 'on' <tr><td>I'm logging in from home</td><td><input type="checkbox" name=" +place"></td></tr> # cgi use strict; use CGI qw(:cgi); use Data::Dumper; my $place = seewhatsthere( data => param('place'), field => 'Place', ); sub seewhatsthere { my %hash = @_; html_start(); print Dumper(%hash); exit(0); }
CASE 1: The checkbox is unchecked
So we get# Dumped $VAR1 = 'Place'; $VAR2 = undef; $VAR3 = 'data'; $VAR4 = 'field';
Place => undef
data => 'field'
which is strange and perhaps incorrect because I was expecting the following
data => undef
field => 'Place'
CASE 2: The checkbox is checked
So we get# Dumped $VAR1 = 'data'; $VAR2 = 'on'; $VAR3 = 'field'; $VAR4 = 'Place';
data => 'on'
field => 'Place'
which is correct.
Thanks :)
update
Thanks to everybody for the wonderful solutions :)
In reply to Strange behaviour - cgi related by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |