Re: How to use multiple checkboxes with the same name in TT / Perl?
Nigel Metheringham <[email protected]> Thu, 28 Jun 2012 10:14:16 +0100
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
This is not a template toolkit issue.
By the looks of it you are using the CGI module to handle this. In
which case the answer is in the first example of the params method:-
https://metacpan.org/module/CGI#FETCHING-THE-VALUE-OR-VALUES-OF-A-SINGLE-NAMED-PARAMETER:
ie use an array to get an array of values:-
@values = $query->param('foo');
BTW this is real 1990s style code - in modern perl for doing web work
you really ought to be using a framework[1] to handle all the
miscellanea of web application development, and some sort of form
handler[2] to deal with building/parsing forms whilst decoupling the
form from the html presentation.
Nigel.
[1] Frameworks -
http://stackoverflow.com/questions/4758009/which-perl-web-framework-should-i-use
has a fair list of frameworks in use and comments on them.
http://www.josetteorama.com/perl/what-is-modern-perl/ also mentions
[2]Form handlers - https://metacpan.org/release/HTML-FormFu and
https://metacpan.org/release/HTML-FormHandler are two, there are others.
Khalid Akram wrote:
> Hi,
>
> I am having an issue using multiple checkboxes with the same name 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;
>
> 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?
>
>
> Thanks
>
>
> Khalid
>
> Web Developer,
>
> Farringdon, London.
>
> This e-mail has been scanned for all viruses by Star.
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
--
[ Nigel Metheringham ------------------------------ [email protected] ]
[ Ellipsis Intangible Technologies ]