memnoch has asked for the wisdom of the Perl Monks concerning the following question:
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:
I see:<input type="hidden" name="run_mode" value="user_results" />
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:<input type="hidden" name="run_mode" value="validate_login" />
And the HTML code displayed with the 'validate_login' run mode is: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;
<!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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Application run mode not being updated with hidden field
by ikegami (Patriarch) on Mar 15, 2008 at 01:34 UTC | |
by memnoch (Scribe) on Mar 15, 2008 at 02:04 UTC | |
|
Re: CGI::Application run mode not being updated with hidden field
by stonecolddevin (Parson) on Mar 15, 2008 at 08:06 UTC |