in reply to Printing variables from CGI form (was: I know this is very easy)
use strict; use CGI; my $CGI = new CGI; print $CGI->header, $CGI->start_html, $CGI->pre; foreach my $name ($CGI->param) { print "$name = ", $CGI->param($name), "\n"; }
When a form is submitted to a Perl script that uses CGI.pm, the form variables are magically available via the param() method.
The param() method works two ways: when called with no args, it returns a list of the available form variables. When called with a single argument(the name of the form variable you want the value of) it returns the value of that variable.
The big gotcha is dealing with multiple-valued variables, then param() will return a list of the values. Change the line inside the for loop to this:
if you want to handle multiple-valued variables. Otherwise the script will only print the last assigned value. Jeffmy $value = join(",", $CGI->param($name)) || ''; print "$name = $value\n";
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: I know this is very easy
by Trimbach (Curate) on Jun 02, 2001 at 04:34 UTC | |
|
Re: (jeffa) Re: I know this is very easy
by mpolo (Chaplain) on Jun 02, 2001 at 10:59 UTC |