kiat has asked for the wisdom of the Perl Monks concerning the following question:
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 :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange behaviour - cgi related
by duff (Parson) on Dec 16, 2003 at 04:36 UTC | |
by kiat (Vicar) on Dec 16, 2003 at 04:46 UTC | |
by duff (Parson) on Dec 16, 2003 at 04:49 UTC | |
by kiat (Vicar) on Dec 16, 2003 at 05:04 UTC | |
by duff (Parson) on Dec 16, 2003 at 15:32 UTC | |
|
Re: Strange behaviour - cgi related
by edoc (Chaplain) on Dec 16, 2003 at 04:55 UTC | |
by duff (Parson) on Dec 16, 2003 at 17:37 UTC | |
|
Re: Strange behaviour - cgi related
by Roger (Parson) on Dec 16, 2003 at 05:45 UTC |