Multiple form parameters of the same name are interpretted by CGI.pm as an
array. The first one to appear in the form is the 0th element and then it
goes on from there. For instance:
<form method='post' action='some_action.cgi'>
<input type='checkbox' name='param1' value='Tea'>
<input type='checkbox' name='param1' value='Coffee'>
<input type='checkbox' name='param1' value='Soft Drinks'>
<input type='checkbox' name='param1' value='Juice'>
<input type='checkbox' name='param1' value='Milk'>
<input type='submit' name='submit' value='Submit This!'>
</form>
If the form is submitted with all these checkboxes checked, then CGI.pm will
create an array that is structured like this:
@param_array = ('Tea', 'Coffee', 'Soft Drinks', 'Juice', 'Milk');
Now if you have a script that looks like this:
#!/path/to/perl -w
use CGI;
use strict;
my $q = new CGI qw(-debug);
foreach ($q->param('param1')) {
print; # prints each element is succession.
print "\n";
}
print "\n\n";
my $param_value = $q->param('param1'); # assigns the first element of the
array, in this case the string 'Tea'.
print "${param_values}\n"; # prints the string 'Tea'.
#---- End test script.
Enter the following command:
perl test_script.pl
The script will pause for input. Enter the following as input:
param1=Tea¶m1=Coffee¶m1=Soft%20Drinks¶m1=Juice¶m1=Milk
Press the return key and then hit CTRL-D (for Unix systems) or CTRL-Z (I
believe for Windows systems) to issue the end of file character so CGI.pm
will stop reading output and the script will continue processing.
The output is below.
#---- Begin output.
Tea
Coffee
Soft Drinks
Juice
Milk
Tea
#---- End output.
The way the param subroutine works in CGI.pm is like this:
1.) if called in scalar context it returns the first element of the array.
2.) if called in array context it returns the entire array.
NOTE: This is not the case with version 3+ of the CGI package of modules.
Version 3+ is ALPHA CODE and shouldn't be used in production servers. This
output was obtained using CGI Version 2.753 which is the latest production
release of the CGI package of modules by Lincoln D. Stein.
Brad Handy
--www.jack-of-all-trades.net
[EMAIL PROTECTED]
> -----Original Message-----
> From: Maxim Berlin [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 17, 2001 8:34 AM
> To: cgi
> Subject: Re: CGI vars
>
>
> Hello Jerry,
>
> Tuesday, July 17, 2001, Jerry Preston <[EMAIL PROTECTED]> wrote:
>
> JP> Hi,
>
> JP> I setup a var to hold data:
>
> JP> $name = $query->param('name');
>
> JP> I get a user input in a textfield.
>
> JP> print $query->popup_menu( -name =>'name',
> JP> -values => $T_NAME{ "\L$fab" },
> JP> -default => ''
> JP> );
> JP> I want to remove it
>
> JP> undef $name;
> JP> print $query->hidden( 'name', $name );
>
> JP> or
>
> JP> print $query->hidden( 'name', "" );
>
> JP> I am unable to drop / delete / clear out the var "name".
>
> JP> What am I doing wrong?
> if i correctly understand, you try to redefine variable inside
> cgi-generated html, yes? i think it is incorrect.
> check, what your browser does with this sample:
>
> **********************
> #!/usr/local/bin/perl
>
> use strict;
> use CGI qw/:all/;
>
> print header;
>
> print <<END;
> <html>
> <head><title>test</title></head>
> <FORM action=$ENV{'SCRIPT_NAME'} method=get>
> <input type=hidden name="param1" value="param1_val">
> <input type=hidden name="param2" value="param2_val">
> <input type=hidden name="param1" value="redefined1">
> <br>
> <INPUT name=submit type=submit value="test">
> </FORM>
> END
>
> print "param1 = ",param("param1"),"<br>";
> print "param2 = ",param("param2"),"<br>";
>
> print '</body></html>';
> **********************
> on my ie5 i got this:
>
> param1 = param1_valredefined1
> param2 = param2_val
>
> Best wishes,
> Maxim mailto:[EMAIL PROTECTED]
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]