Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by MrCromeDome (Deacon)
on Jul 14, 2003 at 04:56 UTC ( [id://273877]=note: print w/replies, xml ) Need Help??


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

For those who may find my end solution helpful, I have posted the code that I have actually used in my project. I thought the reponses given to me were very informative and well thought out, and am very grateful for receving them. I ended up taking a couple of ideas, namely from jeffa and oknow, and from a follow-up chat with tilly. I let my friend do all the HTML design work on this one, and in the end we made a template of the form. As pointed out by ChrisR, the checkboxes in the sample form were named the same, so she cleaned them up and we had a sample form that resembled this:
<tr align="center" bgcolor="#eeeeee"> <td bgcolor="#cccccc"><b>Monday</b> </td> <td width="6%"><input type="checkbox" name="Monday" value="7a8a" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="8a9a" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="9a10a" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="10a11a" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="11a12p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="12p1p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="1p2p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="2p3p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="3p4p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="4p5p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="5p6p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="6p7p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="7p8p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="8p9p" +/> </td> <td width="6%"><input type="checkbox" name="Monday" value="9p10p" +/> </td> </tr>
Each day was passed to my Perl script as an array of checkboxes. Reading and parsing them as parameters was then as easy as:
# Extract and display a summary of information from the form. my @days = qw(Monday Tuesday Wednesday Thursday Friday Saturday Su +nday); foreach my $day (@days) { my @times = $request->param($day); # Count the number of days the user selected something if(scalar @times) { $count += @times; } # Pretty up time times foreach(@times) { s/(\d{1,2}[ap])(\d{1,2}[ap])/\1-\2/; s/(a|p)/\1m/g; } # Display the list for each day $page .= "$day: " . (scalar @times == 0 ? "None" : "@times") . + $request->br(); } # Show the total number of hours selected in the summary $page .= $request->p() . "Total Hours Selected: $count" . $request +->p();
Thanks again to those who took the time to comment on this.

MrCromeDome

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found