Reputation: 21
I have two different Perl CGIs as below which creates two HTMLs.
tes1.pl is called from test.html as a POST call with a param.
test2.pl will be called from test1.pl. But here is the problem, there is a link in test2.pl to test1.pl.
So. when the link is clicked all the POST params will be gone since this runs in a different context.
Can some one let me know how to tackle this situation?
test.html:
<form id = "test" action ="./tes1.pl" method="POST" target="_blank">
<input type="hidden" id='param_sender' name="param1" value="">
</form>
<a onclick="setValue();document.getElementById('test').submit();">SEND THE VALUE</td></tr>
test1.pl:
use CGI;
$page=CGI::new();
my $method=$page->request_method;
if ($method eq "POST") {
my $gpmsc_user=$page->param('param1');
}
print $page->header,
"<link rel='stylesheet' href='./test.css' type='text/css'>";
print $page->start_html(-title=>"TEST1");
test2.pl
my $page= new CGI();
print $page->header,
"<link rel='stylesheet' href='./test.css' type='text/css'>";
print $page->start_html(-title=>'TEST2');
print $page->startform(-method=>post,-action=>'test3.pl');
print $page->append,
"<table border=true>
<tr class=amhead>
<td colspan=3>
<br><a href='test1.pl'>Return to Test1</a>
</td>
</tr>..."
Upvotes: 1
Views: 188
Reputation: 132812
You don't have two CGI programs calling each other. You have a couple of Perl programs that output HTML forms. As such, if you want the one form to have the same parameters in the form, you have to create the HTML in way that has the values set as the default values for those inputs.
With the now-deprecated CGI features,
use CGI qw(:html :form);
my $cgi = CGI->new( 'veggie=tomato' ); # from first form
my $field = 'veggie';
my $value = $cgi->param(
-name => $field,
);
print textfield( # create second form
-name => $field,
-default => $value,
);
This outputs:
<input type="text" name="veggie" value="tomato" />
But, as the CGI
docs note, these HTML generators are deprecated and shouldn't be used. The docs list some alternatives.
Upvotes: 2