Dear Monks,

I have been staring at this for hours and I have no idea what I'm doing wrong. If anyone can help, I'll really appreciate it. The problem is with a CGI::Application run mode not being updated. Here's what happens.

The start_mode ('login_page') displays fine, and it calls the next run mode ('validate_login') through a submit button. The page displayed by 'validate_login' has a submit button in which I specify the next run mode ('user_results') with a hidden field. But in the generated HTML, instead of seeing:

<input type="hidden" name="run_mode" value="user_results" />
I see:
<input type="hidden" name="run_mode" value="validate_login" />
That is, the hidden field still specifies the previous run mode (i.e. 'validate_login'), not what I want (i.e. 'user_results'). My reduced testcase is below:
package Testcase; use base 'CGI::Application'; use CGI::Application::Plugin::DBH qw(dbh_config dbh); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use warnings 'all'; sub setup { my $self = shift; $self->run_modes( 'login_page' => 'show_login_page', 'validate_login' => 'validate_login', 'user_results' => 'show_user_results_page', 'logout' => 'show_logout_page', ); $self->start_mode('login_page'); $self->mode_param('run_mode'); } sub show_login_page { my $self = shift; my $q = $self->query(); my $title = 'Login Page'; my $output = ''; $output .= $q->start_html(-title => $title) . "<h2>$title</h2>\n"; $output .= $q->start_form(); $output .= "Email: " . $q->textfield(-name => 'entered_email', -si +ze => 30, -maxlength => 50) . "<br>\n"; $output .= "Password: " . $q->password_field(-name => 'entered_pas +sword', -size => 20, -maxlength => 20) . "<br>\n"; $output .= $q->submit('Login'); $output .= $q->hidden(-name => 'run_mode', -value => 'validate_log +in'); $output .= $q->end_form; $output .= $q->end_html; return $output; } sub validate_login { my $self = shift; my $q = $self->query(); my $title = "Welcome"; my $output = ''; $output .= $q->start_html(-title => $title) . "<h2>$title</h2>\n"; $output .= $q->p(qq(Welcome! To view your results, click the butt +on below)); $output .= $q->start_form(); $output .= $q->submit('Results'); $output .= $q->hidden(-name => 'run_mode', -value => 'user_results +'); $output .= $q->end_form; $output .= $q->end_html; return $output; } sub show_user_results_page { } sub show_logout_page { } 1;
And the HTML code displayed with the 'validate_login' run mode is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Welcome</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <h2>Welcome</h2> <p>Welcome! To view your results, click the button below</p><form met +hod="post" action="/cgi-bin/testcase/testcase.cgi" enctype="multipart +/form-data"> <input type="submit" name="Results" value="Results" /><input type="hid +den" name="run_mode" value="validate_login" /></form> </body> </html>
Any ideas where the problem is?


In reply to CGI::Application run mode not being updated with hidden field by memnoch

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.