in reply to Checkbox forms

Hello:

I just experienced the same problem as you.

I fixed it by changing the parse form code.
sub parse_form { $query=$ENV{'QUERY_STRING'}; if ($query) { @pairs=split(/&/,$query); } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { $something_in=1; ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; + } else { $INPUT{$name} = $value; } } }



Now we want to put the checkbox list into a array.
@users = split(/,/,$INPUT{'users'});

To print out all the values for the checkboxes that are checked,

foreach $userss (@users) { print <<EOF; $userss<br> EOF }


Hope this helps,
Anthony

Replies are listed 'Best First'.
Re: Re: Checkbox forms
by rob_au (Abbot) on Jun 15, 2002 at 06:54 UTC
    This is not the best way to address this problem of CGI parameter parsing. Your routine will fail for any form where the form checkbox values may contain commas - This is because when you go to split the input into an array, you will end up splitting the passed checkbox value into two separate array elements. This is another reason why you should not hand-roll your own CGI parameter parsers (unless you really know what you are doing and have a justifiable reason to do so -- Personally, I cannot think of any such reasons, but am willing to leave the door open on this on :-)

    Furthermore, the context of the question was to do with the usage of CGI.pm, by far the preferred manner by which to parse CGI parameters - For further details on why this is the case, please see use CGI or die;