Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

submitting a form from within a script

by kstraka (Initiate)
on Apr 11, 2001 at 22:10 UTC ( [id://71783]=perlquestion: print w/replies, xml ) Need Help??

kstraka has asked for the wisdom of the Perl Monks concerning the following question:

OK gang, here's the deal.

I've got a form that's displayed to the user by my script and then is POSTed back onto the same script so it can parse the form data into usable variables.

That's fine and dandy.

What I can't figure out is how to get the script to take that info, in addition to some other info, and then send a GET to a different server and have the result come back to the user. So the user thinks they're getting the result to their original form submission when there was really an intermediate GET they didn't see. Any ideas?

Also, I'm working in an environment where I have no control over the server or any of it's components (college), so any solutions NOT involving installation of modules and the like would be best. Thanks guys.

Replies are listed 'Best First'.
Re: submitting a form from within a script
by twerq (Deacon) on Apr 11, 2001 at 22:28 UTC
    Just off the top of my head, I'm thinkig you could do it the SuperHack(tm) easy way, and create a frame within your page that gets redirected to the external website and shown to the user as if it was a part of your site.

    A better trick would be to use LWP::Simple to get the external page yourself and send the resulting HTML to your client. If you choose the hard(er) route, you might want to consider building the CGI variables right into the URL you pass to the external site in the form of:

    http://external.html.page/externform.cgi?name=myclient&password=hispass&id=10

    . . or maybe this isn't what you want at all.. . .
Re: submitting a form from within a script
by KM (Priest) on Apr 11, 2001 at 22:28 UTC
    Have you looked at the LWP::* modules (LWP::Simple, LWP::UserAgent, etc..)?

    Cheers,
    KM

Re: submitting a form from within a script
by kurt1992 (Novice) on Apr 12, 2001 at 04:44 UTC
    here's a trivial demo that outlines the basics. as the monks have already noted, LWP::Simple is a good solution for GET's. the 'map' statement just forms the foo=somevalue pairs. the get() is an LWP::Simple method that makes the HTTP request and returns the page returned by the remote (or in this case, local) server.
    
    #!/usr/bin/perl -Tw
    use CGI qw( :header :param );
    use LWP::Simple;
    use strict;
    
    my %pairs = ();
    my $remote_script = "http://localhost/cgi-bin/demo.pl"; 
    
    for my $p ( qw( foo bar  ) ) { # assume 'foo' and 'bar' are the params
    $pairs{$p} = param($p);
    }
    
    # there's more than one way to do this . . .
    my @params = map { $_ = $_ . '=' . $pairs{$_} } keys %pairs;
    my $url = $remote_script . '?' . join '&', @params;
    
    print header;
    print "GET'ing $url<p>\n";
    print get($url);
    
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-07-15 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.