Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: form to cgi to cgi

by gam3 (Curate)
on Jan 26, 2008 at 03:21 UTC ( [id://664422]=note: print w/replies, xml ) Need Help??


in reply to form to cgi to cgi

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.

Replies are listed 'Best First'.
Re^2: form to cgi to cgi
by chromatic (Archbishop) on Jan 26, 2008 at 08:54 UTC
    print "content-type: text/html\n\n";

    Most web browsers will probably accept that, but it's invalid HTTP. If you're going to use CGI anyway, why not:

    print $cgi->header();

      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.

Re^2: form to cgi to cgi
by Anonymous Monk on Jan 26, 2008 at 03:50 UTC
    Thank You

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://664422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-16 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found