Click to See Complete Forum and Search --> : CGI::Application


rigadon
06-03-2004, 04:00 AM
Hi everyone!

Just started using CGI::Application as it appears a sensible way to control the flow of my online applications. However, I'm having a few problems with the 'run_mode' parameter. Here's the code for my Run_Mode.pm (called by run_mode.cgi):

package Run_Mode;

use base 'CGI::Application';
use strict;

sub setup {
my $self = shift;
$self->mode_param('rm');
$self->run_modes('rm1' => 'input_file',
'rm2' => 'input_mappings',
'rm3' => 'confirm');
$self->start_mode('rm1');
}

sub teardown {
my $self = shift;
}

sub input_file {
my $self = shift;

# get CGI query object
my $q = $self->query();

my $result = $q->start_html();

$result .= "<p>(input_file) - " . $q->param('rm') . "</p>";

$result .= $q->start_multipart_form();
$result .= $q->hidden(-name => 'rm', -value => 'rm2');
$result .= $q->submit(-value => 'Submit');
$result .= $q->end_form();
$result .= $q->end_html();

return $result;
}

sub input_mappings {
my $self = shift;

# get CGI query object
my $q = $self->query;

my $result = $q->start_html();

$result .= "<p>(input_mappings) - " . $q->param('rm') . "</p>";

$result .= $q->start_multipart_form();
$result .= $q->hidden(-name => 'rm', -value => 'rm3');
$result .= $q->submit(-value => 'Submit');
$result .= $q->end_form();
$result .= $q->end_html();

return $result;
}

sub confirm {
my $self = shift;

# get CGI query object
my $q = $self->query;

my $result = $q->start_html();

$result .= "<p>(confirm) - " . $q->param('rm') . "</p>";

return $result;
}

1;

So this should just step through until I reach the confirm mode. However, it instead submits the 'input_file' stage then repeatedly submits the 'input_mappings' stage to itself. You'll note that I have incremented the 'rm' parameter as required. When I look at the html generated for the 'input_mappings' mode the value of 'rm' is still 'rm2' rather than 'rm3' as I have specified in the:

$result .= $q->hidden(-name => 'rm', -value => 'rm3');

line. The problem must be here since if I do the following instead:

$result .= "<input type=\"hidden\" name=\"rm\" value=\"rm3\">";

it works fine - but I'd like to keep the $q->hidden format if at all possible...

Hope someone can help!!