A CGI program accepts inputs from the browser, processes them in some way and then produces an output (which is usually an HTML page to be displayed by the browser).
There is no reason why the HTML produced by the CGI program can't include another form which will then call another CGI program (or even the same CGI program again).
If you're calling the same CGI program to handle different stages of a process, then you need to give it some way to distinguish which stage each call needs to process. The easiest way to do this is to have a hidden input (I usually call it 'mode') on the form.
I often find myself writing CGI programs that look a bit like this:
#!/usr/bin/perl
use strict;
use warnings;
use CGI ':cgi';
use Template; # for producing output.
# List of subroutines that handle the different modes
my %modes = (
mode1 => \&process_mode1,
mode2 => \&process_mode2,
default => \&process_default,
);
# Work out which mode we're in
my $mode = param('mode');
# If we have a mode, then call that subroutine
if ($mode && %modes{$mode}) {
$modes{mode}->();
} else {
# Otherwise call the default handler
$modes{default}->();
}
sub process_default {
# no mode give, display the default form
}
sub process_mode1 {
# process mode1 and display the next form
}
sub process_mode2 {
# process mode2 and display the next form
}
The output templates are either stored in external files, or in the DATA section using Inline::Files.
Of course, these days, you're probably better off using a framework like Catalyst.
Update: Fixed problems noted by blazar below.
|