Re: How to use multiple checkboxes with the same name in TT / Perl?
Dave Howorth <dhoworth-fDajt2Yx3S8pY9vWkoisglpr/1R2p/[email protected]> Thu, 28 Jun 2012 10:07:05 +0100
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Organization | MRC Laboratory for Molecular Biology |
| Message-ID | <[email protected]> |
Khalid Akram wrote: > Hi, > > I am having an issue using multiple checkboxes with the same name with TT. Well firstly, this has nothing to do with TT! > If I have some checkboxes like this: > > <input type="checkbox" name="options" value="1"> > <input type="checkbox" name="options" value="2"> > <input type="checkbox" name="options" value="3"> > > If I select 3 of these and submit, what gets posted to the CGI is this: > > options=1&options=2&options=3; And that is exactly what you would expect, no? If not, you need to read up about HTML forms. > In my receiving script I have: > > my $options = $query->param( "options" ); > > which only gives me the first value!! What I need is a comma separated list that I can then loop over. > > What is the best way around this? You're using CGI.pm or some replacement, yes? (You don't say, so I have to guess :( ) So if you look in its perldoc, it says: "Pass the param() method a single argument to fetch the value of the named parameter. If the parameter is multivalued (e.g. from multiple selections in a scrolling list), you can ask to receive an array. Otherwise the method will return a single value." So it is behaving as it's supposed to, no? And what you need to do is assign to an array instead of a scalar, to get the list of values. Cheers, Dave