Link to home
Start Free TrialLog in
Avatar of gnagabandi
gnagabandi

asked on

How to cause form submit action in perl.

My perl program takes one HTML file which contains a form as input. Then it changes the ACTION by using parse module to point another perl/CGI program. Now how can I cause submit action dynamically in perl to invoke the program? The program has to take all the form parameters as input. If LWP module is the solution, how I have to use LWP? Any suggestion will be greatly appreciated.

Gangadhar
Avatar of gnagabandi
gnagabandi

ASKER

Edited text of question.
Avatar of ozo
Here's an example that I wrote up for someone a week ago for a very similar question regarding a CGI script invoking another CGI script.  It demonstrates the use of a POST.  

The html form sends it output to testmove.pl, testmove.pl receives it and reposts it to the Experts-Exchange search engine.  The resulting page is altered slightly :-) and displayed.

Here's the html page which references the first cgi
----------------------------------------
<html>
<body>
Search EE:<BR>
<form action="testmove.pl" method="post">
<input type=hidden name=ta value="57">
<input type=text size=30 name=search value=""><BR>
<input type=radio name=everything value="" checked>&nbsp;&nbsp;Search CGI Topic Area<br>
<input type=radio name=everything value=1>&nbsp;&nbsp;Search Everything<BR>
<input type="submit">
</form>
</body>
</html>

Here's testmove.pl
----------------------------------------
  use HTTP::Request::Common qw(POST);
  use LWP::UserAgent;
  use CGI;

  $myCGI = new CGI;
  $ua = new LWP::UserAgent;

# Create a hash of all the parameters
  foreach ($myCGI->param) { $myparams{$_} = $myCGI->param($_); }

  my $req = POST 'https://www.experts-exchange.com/bin/SimpleSearch', [ %myparams ];
   
  my $page = $ua->request($req)->as_string;

  $page =~ s#</head>#<base href="https://www.experts-exchange.com/"></head>#i;

  $page =~ s/Experts Exchange/Clockwatcher's/g;


  print $page;

----------------------------------------

If my server happens to be up, you can check it out at:

  http://experts-exchange.yahright.com/10224657/
You can generate a lot type of forms. What actually is the type of the form that you want for there's always different type of handling between data-recording form, mailing form, info form, search-engine type form etc etc.

- MasterGaurav
I want to describe my problem with more details. My perl program takes one html file as input(right now CGI doesn't come in to picture). The html file contains one form with some input fields as empty. Then by using other perl subroutine I filled some form parameters and also changed the action to invoke other CGI program. In the next step, I have to execute/invoke the CGI program in this same perl script(as if we submit online forms), which has to take all the form parameters as input.

 My form is just info type. All the above tasks should be done at a single stretch. How to invoke the program to cause submit action of the html form.

 I have some restriction with using LWP::UserAgent, as I have to prepare the entire form parameter list(because I am reading directly from HTML file). If I had submit the HTML form by online, I would have all the parameter list available in array form.

 Is there any way to cause dynamic submit action in perl. I will be greatful to you for any solution.
ASKER CERTIFIED SOLUTION
Avatar of prakashk021799
prakashk021799

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial