Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Can't modify variable received from CGI parameter

by Anonymous Monk
on Sep 09, 2003 at 00:02 UTC ( [id://289912]=perlquestion: print w/replies, xml ) Need Help??

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

Weirdness.... I take in a parameter and modify it. When I try to pass it on to another CGI, it doesn't pass....

use CGI qw/:standard/; use strict; my $cgi = new CGI; my $species = param('species'); $species = 'Not Rat'; print $cgi->header(), $cgi->start_html(), $species, $cgi->hidden( -name => 'species', -default=> $species, ), $cgi->end_html();

On screen it displays "Not Rat", but the value in my hidden field is "Rat". What gives? Is this a CGI.pm feature? I scanned the perldoc but didn't see anything like this, but I didn't know what exactly I was looking for....

Replies are listed 'Best First'.
Re: Can't modify variable received from CGI parameter
by menolly (Hermit) on Sep 09, 2003 at 00:29 UTC

    As per the documentation:

    Note, that just like all the other form elements, the value of a hidden field is "sticky". If you want to replace a hidden field with some other values after the script has been called once you'll have to do it manually:
    $query->param('hidden_name','new','values','here');

    Add

    $cgi->param('species', $species);
    at some point before you print the field.

Re: Can't modify variable received from CGI parameter
by benn (Vicar) on Sep 09, 2003 at 10:41 UTC
    Altenatively, you could use the '-override' flag, which emoves the stickiness and forces CGI.pm to always use the 'default' value.
    print $cgi->hidden( -name => 'species', -default=> $species, -override => 1, );
    Cheers, Ben.
Re: Can't modify variable received from CGI parameter
by Anonymous Monk on Sep 09, 2003 at 13:54 UTC
    Thanks gentleman, somehow I wasn't thinking this was a function of the field, but of the parameter: I skipped over stickiness without even reading it. The help is much appreciated.

Log In?
Username:
Password:

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

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

    No recent polls found