PDA

View Full Version : How to code a cgi script to accept multiple checkbox values?


genx_000
07-19-2008, 12:12 AM
Hi,

I'm trying to figure out an efficient way to accept multiple user input via checkbox input using cgi. cant figure out how?

Ex: say you have 60 checkboxes, each check box corresponds to a number, like a number picker. From the 60 ccheckboxes the user is allowed to pick only 13. When the user picks the 13 numbers the values for each of those checkboxes is passed on to the script.

You ca create 60 variables to hold all the 60 values but that is just poor programming. Can you help me figure out a better efficient way?

Thank you.

gen_x

FishMonger
07-19-2008, 01:29 AM
Use the same value for the name attribute for all 60 of the checkboxes. Then you can retrieve them as an array. The synopsis section the CGI module's documentation gives an example. If you retrieve the from fields as a hash, then you'll need to split the field by the "\0" (null) character.
http://search.cpan.org/~lds/CGI.pm-3.38/CGI.pm#FETCHING_THE_PARAMETER_LIST_AS_A_HASH:

genx_000
07-19-2008, 04:44 AM
thank you so much for your advice...