Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

A newbie's CGI- kinda problem

by mikkoh (Beadle)
on May 26, 2000 at 16:07 UTC ( [id://14949]=perlquestion: print w/replies, xml ) Need Help??

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

I have a mail script that takes input from a few forms, of which one has a checkbox-group. I'm in a situation where I need to write out the parameters in a single string, like so:

foreach($q->param()){ if(/^[\w\d]+/){ $stuff .= $_; $stuff .= ":"; $stuff .= $q->param("$_"); $stuff .= "\n\n"; } }

The problem is with the checkboxes, only the first given value gets appended to the string. Like if the string was:

list:foo,bar,foobar

the string is set to

list:foo

I'm probably just missing something simple, but I've tried pretty much everything I know. I'd appreciate some comments..

Replies are listed 'Best First'.
Re: A newbie's CGI- kinda problem
by httptech (Chaplain) on May 26, 2000 at 17:57 UTC
    If you want to dump all params in list context you could use something like: print map {"$_ : @{[$q->param($_)]}\n"} $q->param;
Re: A newbie's CGI- kinda problem
by comatose (Monk) on May 26, 2000 at 17:27 UTC

    Checkboxes are returned as lists. In order to get the values of a group of checkboxes named "list", you'd need:

    @values = $q->param('list');

    This is covered in the CGI.pm documentation.

      Thanks, but one problem is that I don't want to name any specific param, as the script is supposed to blindly go through them all never mind what they are. Thanks anyway - problem solved :) //mjh
Re: A newbie's CGI- kinda problem
by anders (Initiate) on May 26, 2000 at 17:59 UTC
    Hi,
    The CGI module returns the list on request, using wantarray to determine your wishes. See the CGI docs.
    just modify your code a bit:
    foreach($q->param()){
      if(/^\w\d+/){
        $stuff .= $_; $stuff .= ":";
        my @v;
        $stuff .= join ',', (@v = $q->param("$_"));
        $stuff .= "\n\n";
      }
    }
    
    -anders
      Thanks! Works like a charm. I knew it had to be something quite simple -- just need more caffeine.. X-) //mjh
RE: A newbie's CGI- kinda problem
by agoth (Chaplain) on May 26, 2000 at 18:02 UTC
    print $q->Vars; takes care of it all for you
      Hmm, looks like the Vars subroutine is not available in the version of CGI.pm that shipped with perl 5.00503 on my Linux box. Upon upgrading it I found it, but printing $q->Vars returns everything contencated into one long string with no spaces; not very useful. You'd have to call it in another context and do some interim processing to get it to spit out a neat, human readable list it looks like.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-07-22 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.