Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: cgi: Grabbing Multiple input values

by andreychek (Parson)
on Jul 03, 2001 at 19:04 UTC ( [id://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.
-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"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-03-28 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found