Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Looping over all checked boxes w/ CGI.pm

by Anonymous Monk
on Mar 21, 2002 at 19:21 UTC ( #153391=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have a very simple question that has bugged me on more than one occasion - i am printing a list of checkboxes, now what I want to do is scan all the check boxes and remove and files that are checked

I have tried a:
while ( $query->param() ) { # .. snip.. (delete if checked) }
but this starts an everlasting loop and the program just hangs..any thoughts?

Thanks

Title edit by tye

Replies are listed 'Best First'.
(Ovid) Re: Very Simply
by Ovid (Cardinal) on Mar 21, 2002 at 19:24 UTC

    while will execute while a condition evaluates as true. What you want to do is iterate over your params. foreach is one way to do this:

    foreach ( $query->param ) { # do stuff }

    However, I would look down on this in a code review (probably) as one typically needs to treat each parameter as a special case and untaint it according to your needs. Iterating over all of the parameters suggests that this is not being done.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Very Simply
by earthboundmisfit (Chaplain) on Mar 21, 2002 at 19:43 UTC
    There are a lot of ways to do it. You only want the check boxes, so what I would do is first check to make sure all my checkboxes have the same name and then store them in an array like this:
    #! Perl -w use strict; use CGI; my $q = new CGI; my @checkbxs = $q->param('the_name'); # only those that are checked en +d up in here for (@checkbxs) { &delete_file($_); # assuming a delete sub exists }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-10-06 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (26 votes). Check out past polls.

    Notices?