Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Converting large numbers of checkboxes to small number of params by ChrisR
in thread Converting large numbers of checkboxes to small number of params by MrCromeDome

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2022-12-05 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?