The problem you are facing is not the result of the behaviour of CGI::Application, but rather that of the "sticky" behaviour of CGI.pm when used for hidden form field generation.

From the CGI.pm POD ...

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');

As such, you will need to force the change in the runmode hidden form field value via something like $q->param('runmode', 'mode3'), for example ...

sub bar { my $self = shift ; my $q = $self->query() ; my $output = '' ; my $first_number = $q->param( 'first_number' ) ; $q->param( 'runmode', 'mode3' ); $output .= $q->start_html( "Bar" ) ; $output .= $q->h2( 'I\'m webapp run mode number two.' ) ; $output .= $q->h2( 'You click me and I\'ll click you!' ) ; $output .= $q->start_form ; $output .= $q->h3( 'Gimme another number!' ) ; $output .= $q->textfield( -name => 'second_number' ); $output .= $q->hidden( -name => 'first_number', -value => $first_number ); $output .= $q->hidden( -name => 'runmode', -value => 'mode3' ); $output .= $q->submit(); $output .= $q->end_form(); $output .= $q->end_html(); return $output; }

Alternatively, you could make use of the templating features offered by HTML::Template which is integrated with this framework - I would advocate this approach as the combination of the framework provided by CGI::Application and the flexibility offered by page template allows for great ease in rapid prototyping. If your preferred templating system is not HTML::Template however, you can make use of an alternate framework such as Template Toolkit in a fashion very similar to that I have described here.

 

Update - Added code example to demonstrate the inclusion of $q->param('runmode', 'mode3') in the bar subroutine.

 


In reply to Re: CGI::Application Run Modes by rob_au
in thread CGI::Application Run Modes by DamnDirtyApe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.