http://qs321.pair.com?node_id=93531


in reply to cgi: Grabbing Multiple input values

I think the problem may be with your naming scheme. As opposed to naming the select box something like "input", try naming it:
input[]; For the full example: <form> <select NAME="input[]" SIZE=3 MULTIPLE> <option VALUE="opt1">option1 <option VALUE="opt2">option2 <option SELECTED VALUE="opt3">option3 </select> </form>
And then when it gets to your Perl script, you can treat it as an array. Otherwise, your Perl script really does only see it as one value.
-Eric

UPDATE Okay, maybe it's time to kick myself for having a PHP background before I came around to the Perl world :-)

However, what would the proper method be in this scenerio -- If I used HTML::Template to build my template, and CGI.pm to process them.. in that case, what would be the proper thing to name the SELECT element?
a. <select name="myname" multiple> b. <select name="myname[]" multiple>
Thanks! :-)

Replies are listed 'Best First'.
Re: Re: cgi: Grabbing Multiple input values
by Anonymous Monk on Jul 03, 2001 at 23:59 UTC
    You would name it whatever you want. You would then access multiple valuse by assigning to an array when requesting the values:
    my @selected = $query->param("my_multiple_select");
    Or just use it in a list context:
    foreach my $sel ( @{$query->param("select")} ){ ... }
    You might also want to name it myname[] just to remind yourself that multiple values are allowed.

    Have a look at CGI::State. If you follow a naming convention it sets out it will take a CGI.pm query object and turn it into a multidimensional data structure.

    The name is off and it wouldn't be the best thing for maintainability but I can see how it could be handy.

    Clayton aka "tex"