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

CGI hidden input value wrongly assigned.

by jck (Scribe)
on Jun 13, 2006 at 04:14 UTC ( [id://554947]=perlquestion: print w/replies, xml ) Need Help??

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

i'm going crazy....can someone tell me what's going on here? my code:
print p("line 109"); print start_form({ -action => "$thisscript", -method => "post" }); print hidden('action','logout'); print submit('Logout'); print end_form; print p("line 115");
the resulting HTML:
line 109 </p> <form method="post" action="ti_login.pl" enctype="multipart/form-data" +> <input type="hidden" name="action" value="login" /><input type="submi +t" tabindex="1" name="Logout" value="Logout" /><div></div></form><p> line 115

why is it assigning the value to the hidden input "action" as "login", when it should be "logout"??

i do have another conditional loop in the script that assigns the hidden input named "action" to the value "login", and that's why i put the silly print lines in to make sure i was not looping out to another part of the code inadvertantly...

any help appreciated, and my apologies in advance for raising such a ridiculous problem to great minds here, but i'm out of ideas!! (and stumped as to what could be happening) TIA

Replies are listed 'Best First'.
Re: CGI hidden input value wrongly assigned.
by Zaxo (Archbishop) on Jun 13, 2006 at 04:50 UTC

    It's possible that a hidden "action=login" is getting in through CGI's "sticky" state mechanism. Since a logout opportunity is generally preceeded by a login, it may even be likely.

    See the CGI.pm pod for details of how to control that.

    After Compline,
    Zaxo

      If so, the fix is to change
      print hidden('action', 'logout');
      to
      print hidden(-name => 'action', -value => 'logout', -override => 1);

        Thanks to all for the help.

        Looking at CGI.pm documentation, i found the -nosticky pragma, and tried that, but it didn't solve the problem. oddly enough, in the actual loops of the script, $action gets defined as 'logout' before it ever sees $action='login', but, of course, in order to be logged in, you have to have set that action in a previous call to the script. Unfortunately, just adding the -nosticky pragma didn't solve the problem.

        adding the -override element to the hidden field worked great!!

        so, i'm still perplexed as to the behaviour, since i've used loops like this in the past with no problems, but since it's working at the moment, i won't complain!!

        again, thanks for leading me out of the woods. jck

Re: CGI hidden input value wrongly assigned.
by mbadolato (Hermit) on Jun 13, 2006 at 04:42 UTC
    Check your conditionals and make sure nothing is executing that you think isn't. I just copied your above code:
    use CGI qw/:standard/; $thisscript = 'foo'; print p("line 109"); print start_form({ -action => "$thisscript", -method => "post" }); print hidden('action','logout'); print submit('Logout'); print end_form; print p("line 115");
    When I ran, I got the expected result:
    <p>line 109</p><form method="post" action="foo" enctype="multipart/for +m-data"> <input type="hidden" name="action" value="logout" /><input type="subm +it" name="Logout" value="Logout" /></form><p>line 115</p>
    So something is running that you think isn't.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found