Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: cgi: Grabbing Multiple input values

by andreychek (Parson)
on Jul 03, 2001 at 19:04 UTC ( #93531=note: print w/replies, xml ) Need Help??

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.

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 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 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"

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-10-28 02:34 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (259 votes). Check out past polls.