Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

CGI::Application is ignoring me

by Anonymous Monk
on Jul 21, 2005 at 02:03 UTC ( #476690=perlquestion: print w/replies, xml ) Need Help??

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

I don't get it - Why does CGI::Application hate me?
package run_mode_test; use strict; use base qw/CGI::Application/ ; use CGI qw/:standard/; sub setup { my $self =shift; $self->start_mode('page1'); $self->run_modes('page1' => 'page1', 'page2' => 'page2'); } sub page1 { my $self =shift; my $q = $self->query(); my $output = ''; $output .= $q->start_html(-title => 'Test Run Mode'); $output .= 'this is page1'; $output .= $q->start_form(); $output .= $q->hidden(-name => 'rm', -value => 'page2'); $output .= $q->submit(); $output .= $q->end_form(); $output .= $q->end_html(); return $output; } sub page2 { my $self =shift; my $q = $self->query(); my $output = ''; $output .= $q->start_html(-title => 'Test Run Mode'); $output .= 'this is page2'; $output .= $q->start_form(); $output .= $q->hidden(-name => 'rm', -value => 'page1'); $output .= $q->submit(); $output .= $q->end_form(); $output .= $q->end_html(); return $output; } 1;
page1 displays properly, when submitted it brings up page 2. Page2 however has the hidden rm field set to page2.

Replies are listed 'Best First'.
Re: CGI::Application is ignoring me
by Hero Zzyzzx (Curate) on Jul 21, 2005 at 02:15 UTC

    This isn't CGI::Applications fault. You're seeing the "sticky form" behaviour that is the default for CGI.pm. Read the docs, looking specifically for the "override" parameter.

    "Sticky forms" make programming dynamic forms easier (because CGI.pm remembers form values between invocations, making the "submit/validate/action" cycle easier), but it can on occasion bite you in the butt. Your "rm" value never gets changed because CGI.pm is remembering it. Override will force your new value to take precedence.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

    My Biz

Re: CGI::Application is ignoring me
by cees (Curate) on Jul 21, 2005 at 13:34 UTC

    You have your answer already, but I'd like to point something else out that may bite you later on. You should really consider removing the use CGI qw/:standard/; line from your code. That imports a whole slew of functions into your namespace, including one called 'param'. CGI::Application already has a 'param' method, and you are replacing it with CGI.pm's param method. If you start depending on CGI::Application's param method in the future, bad things will start happening, cause it will invoke the wrong function when you call $self->param.

    Unless you actually want to use the CGI.pm functions in your code, you shouldn't need to import anything. CGI::Application already gives you a CGI.pm query object to get your parameters. If you really want to use the html helper functions, think of fully qualifying them instead (CGI::h1, CGI::popup_menu, etc...). Or if you really want those functions imported, try to just import the functions that you need (use CGI qw/:html/)

Re: CGI::Application is ignoring me
by samtregar (Abbot) on Jul 21, 2005 at 18:43 UTC
    That's easy, CGI::Application hates you because you're not using templates. CGI::Application and HTML::Template have been dating since high-school and they don't take kindly to people that try to break them up.

    -sam

      And they've been introduced to some other friends (HTML::FillInForm, Data::FormValidator) to handle creating sticky forms and still keep the HTML in templates. They're a pretty tight group of friends.

      -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2021-05-07 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (92 votes). Check out past polls.

    Notices?