Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Reading Checkboxes

by greywolf (Priest)
on Nov 05, 2001 at 11:26 UTC ( [id://123292]=note: print w/replies, xml ) Need Help??


in reply to Reading Checkboxes

HMTL tip coming up:
All the checkboxes in the form must have different names. If they have the same name you will only get one value = 'on', even if all boxes are checked.

Update:
I stand corrected. The broken solution presented by Fastolfe is what I have had to use at work. I will have to try ColtsFoots solution next time around.

mr greywolf

Replies are listed 'Best First'.
Re: Re: Reading Checkboxes
by ColtsFoot (Chaplain) on Nov 05, 2001 at 12:50 UTC
    This does not seem to be the case, the following code
    #!/usr/bin/perl -w use strict; use CGI; my $cgi = new CGI; print $cgi->header(); print $cgi->start_html(); my $submit = $cgi->param('submit'); if ($submit) { my @on = $cgi->param('desig'); foreach my $item (@on) { print qq($item<BR>); } exit; } print $cgi->startform(-method=>'post'); print $cgi->checkbox_group(-name=>'desig', -values=>['a', 'b', 'c', 'd', 'e', 'f', 'g']); print $cgi->submit(-name=>'submit', -value=>'Submit'); print $cgi->endform(); print $cgi->end_html();
    yields
    a c e g
    when every other box is checked
Re: Re: Reading Checkboxes
by Fastolfe (Vicar) on Nov 05, 2001 at 21:33 UTC
    Only if you're using a broken/proprietary CGI parameter parsing routine that does something like this:
    foreach my $pair (split /&/, $ENV{QUERY_STRING}) { my ($key, $value) = split(/=/, $pair); $parameters{$key} = $value; }
    The correct solution is to defer processing like this to CGI.pm, which will correctly handle multiple checkboxes with the same name.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://123292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found