Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Converting large numbers of checkboxes to small number of params

by ChrisR (Hermit)
on Jul 09, 2003 at 20:54 UTC ( #272827=note: print w/replies, xml ) Need Help??


in reply to Converting large numbers of checkboxes to small number of params

I took a look at the web page and noticed one thing up front that will probably cause you some difficulty. Each checkbox has the same name. This will make it impossible to distinguish one from another. Your best be here is to come up with a naming convention for the checkboxes. I would use the day follwed by a delimeter follwed by the hour. For example: monday-7, monday-8 ... monday-16, monday-17, tuesday-7, tuesday-8, etc.

I don't think you will find a way to avoid having a different name for each checkbox. You can still use a loop to create the form quite easily without a lot of code.

Parsing the query string out can be made very simple as well. Try this snippet:
if ($ENV{'QUERY_STRING'} ne '') { # for get requests $webparams = "$ENV{'QUERY_STRING'}"; } else { # for post requests (you should always use post) read(STDIN, $webparams, $ENV{'CONTENT_LENGTH'}); } $webparams =~ s/\&/\n/g; $_ = $webparams; %webparams2 = /^(.*?)=(.*)$/gm;
This will return a hash (%webparams2) containg an entry for every checkbox that was checked when the form was submitted. The keys will be the names of the checkboxes. Now you can just loop through the hash or use map to create your database statement.

I hope this helps. If you would like a more complete example including form generation and db statement preparation, just let me know.

Chris
  • Comment on Re: Converting large numbers of checkboxes to small number of params
  • Download Code

Replies are listed 'Best First'.
Re: Re: Converting large numbers of checkboxes to small number of params
by ChrisR (Hermit) on Jul 09, 2003 at 21:08 UTC
    Another good idea might be to make the names of you checkboxes match the field names in your db. That would slightly reduce the code needed to create the statement.

    Please excuse the second post but I don't know how to update it. Perhaps someone can tell me?

    Chris

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-12-09 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?