Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

CGI: List all params

by Structed (Novice)
on Dec 12, 2007 at 11:22 UTC ( [id://656590]=perlquestion: print w/replies, xml ) Need Help??

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

Dear wise Monks, is there a function/a way to list all params of CGI POSTed/GETed (^^) ) from a form? If not, how can I do it?

Replies are listed 'Best First'.
Re: CGI: List all params
by pfaut (Priest) on Dec 12, 2007 at 11:31 UTC

    It's right there in the CGI documentation (perldoc CGI):

    FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT: @names = $query->param If the script was invoked with a parameter list (e.g. "name1=value1&name2=value2&name3=value3"), the param() method w +ill return the parameter names as a list. If the script was invoke +d as an <ISINDEX> script and contains a string without ampersands (e.g. "value1+value2+value3") , there will be a single parameter name +d "key- words" containing the "+"-delimited keywords.
    90% of every Perl application is already written.
    dragonchild
Re: CGI: List all params
by moritz (Cardinal) on Dec 12, 2007 at 11:30 UTC
    From CGI:
    FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT: @names = $query->param

    Iirc that this will return only POST parameters if there are any POST parameters, so you might want to check for url_param as well.

Re: CGI: List all params
by Thilosophy (Curate) on Dec 12, 2007 at 11:31 UTC
    If you are using CGI.pm, you can say
    my @names = $query->param;
    to get the names of all the parameters (and then proceed to fetch the values one by one).
      Could you explain how we can "proceed to fetch the values one by one"? All I can do right now is just get the list of the variables...but I can't actually get their values. Sorry to reply to such an old post. Thank you in advance!
        but I can't actually get their values. Sorry to reply to such an old post. Thank you in advance!

        That is because you skipped the requisite reading step. CGI. Basically, you give param an argument, it returns values.

        foreach $name ( @names ) { if ( $name =~ /\_/ ) { next; } else { print "

        ".$name."\t=\t".$query->param($name) . "

        \n"; } some thing like this you can do

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found