Re: form to cgi to cgi
by gam3 (Curate) on Jan 26, 2008 at 03:21 UTC
|
There are lots of ways to do this, but here is a start
#!/usr/bin/perl
use strict;
use CGI;
my $cgi = CGI->new();
print $cgi->header();
print <<EOP;
<html>
<head>
<title>test</title>
</head>
<body>
<div>
<h1>Please input data below</h1>
<form>
Name: <input name="testdata" text="name"/>
<form>
</div>
</body>
</html>
EOP
use Data::Dumper;
use HTML::Form;
use LWP::UserAgent;
if (my $data = $cgi->param('testdata')) {
my $ua = LWP::UserAgent->new;
print "got: " . $data;
print "<br/>";
my $html = "http://localhost/cgi-bin/test";
# http://localhost/y.cgi is where the socond form is submitted.
my $form = HTML::Form->parse(<<HTML, 'http://localhost/');
<form action="/y.cgi">
<intput type="text name="test" />
</form>
HTML
$form->attr( 'test', $data);
my $response = $ua->request($form->click);
print Dumper $response;
print "<br/>";
}
1;
I hope there are enough hints here to get you going.
You might also just want to get the form from the page then fill it out.
UPDATE: Took chromatics suggestion and now use header().
-- gam3
A picture is worth a thousand words, but takes 200K.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Then it's fortunate his script is communicating using CGI (not HTTP) with a web server (not a browser).
While the header CGI is defined as being an HTTP header, web servers have a long history of accepting "\n" as a CGI header line seperator. The CGI spec even mentions it allows the CGI header to be seperated from the CGI body by LF or by CRLF. It's up to the server to construct a valid HTTP response from that de-facto valid CGI request.
Or if you're referring to the unusual text case, CGI/HTTP field names are case-insensitive (RFC2616 S4.2). Incidentally, so are media types and subtypes (RFC2616 S3.7).
While using print $cgi->header(); is a great idea seeing as CGI is already in play, what his script does is by no means invalid.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
Re: form to cgi to cgi
by ww (Archbishop) on Jan 26, 2008 at 02:44 UTC
|
| [reply] [Watch: Dir/Any] |
Re: form to cgi to cgi
by olus (Curate) on Jan 26, 2008 at 02:38 UTC
|
You'll have to make yourself clearer.
We need a better description to your problem in order to be able to assist you.
Please read How (Not) To Ask A Question for some guidance.
And why do you need to post from one cgi to the other? | [reply] [Watch: Dir/Any] |
|
Sorry let me try this again
at stage one i submit a form
First name
Last name
ect.
that posts to ord.cgi
that works all find and dandy but now my father is holding me hostage until i can figure out how to catch the form in another cgi that sends it to ord.cgi but ive been looking for several days through manuals and cant find the necessary commands to have the first cgi catch the form? thanks for any help.
| [reply] [Watch: Dir/Any] |
|
Did your father specify that you send it back to the *SAME* script as receives the first (for further processing, to capture additional data, ???), as your parent post seems to say?
Eminently doable, but if you're new to Perl, you may find it easier to write two scripts.
Script 1, ord.cgi (according to one reading of your post) will need to be enhanced to catch First name Last Name, etc. and to pass those on to script 2, perhaps (if you're going to do this with an intermediate page requesting additional information) as elements -- possibly hidden -- of a new webpage to be created by script 2. Then, extend script 2 so as to catch both the previously captured elements -- the names, etc -- and to pass the aggregate on to either yet-another-new-page or yet another script.
On the other hand, the final part of your question (after your assertion that you've been searching you say "cant find the necessary commands to have the first cgi catch the form" (sic) ) seems to say that you have not yet figured out how to have script 1 catch elements of your form... so I may be way off track on what you're looking for.
So please. Think your problem through, and then, post again. And not to be snarky about it (yes, I make typos, misspellings and careless errors, too), please write using well-formed (eg, not run-on) sentences and paragraphs that structure your questions for the reader in a clear and coherent manner with correct spelling and punctuation.
NB: FWIW, the parent of this node, and this node, were posted after my next one was posted.
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: form to cgi to cgi
by bradcathey (Prior) on Jan 26, 2008 at 15:27 UTC
|
<form action="foo1.pl" method="post">
<input type="text" name="firstname" />
<input type="text" name="lastname" />
<input type="submit" />
</form>
PERL foo1.pl:
#!/usr/bin/perl
use strict;
use CGI qw /:cgi/;
use HTML::Template;
my $query = new CGI;
$template = HTML::Template->new( filename => 'form2.tmpl' );
$template -> param( firstname => $query->param('firstname'),
lastname => $query->param('lastname')
);
print $template->output;
HTML form2.tmpl:
<form action="foo2.pl" method="post">
<input type="text" name="firstname" value="<tmpl_var firstname>" />
<input type="text" name="lastname" value="<tmpl_var lastname>" />
<input type="submit" />
</form>
And if you are using selects, checkboxes, or radio buttons, HTML::FillInForm is great. Hope your father approves.
—Brad "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
| [reply] [Watch: Dir/Any] [d/l] [select] |