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

Hi Monks,
I want to use some web tools for my research and I'm trying to set up a script to run them over the web, without the need of copy-pasting each time. Can you help me on what to do in order to start? Imagine that the tools usually have a form where you put your data and you hit submit. Then you are presented with the page results, which I would like either to be able to download or store it into another variable maybe? Thanks!
  • Comment on How to run scripts on the web filling out forms?

Replies are listed 'Best First'.
Re: How to run scripts on the web filling out forms?
by marto (Cardinal) on Dec 01, 2011 at 18:24 UTC
Re: How to run scripts on the web filling out forms?
by TJPride (Pilgrim) on Dec 02, 2011 at 03:45 UTC
    Something like this, only a more advanced form fields module might be better if you're doing a professional app rather than a quick hack, and you'd want to put your site design in a template file rather than just hard-coding it here.
    #!/usr/bin/perl use CGI qw(:standard); use strict; use warnings; my (@errors, %data, %forms); ### Validate fields if (param('submitted')) { $data{$_} = param($_) for param(); ### Do whatever convertions on %data push @errors, 'My field is required.' if !$data{'myfield'}; } ### Process form data somehow if (param('submitted') && $#errors == -1) { ### Do something, like submit to database or display result ### Forward to another page, or display form again by just ### letting it run through to the bottom } ### Generate form fields, filling in previous values $forms{'myfield'} = textfield(-name => 'myfield', -value => $data{'myf +ield'}, -size => 10, -maxlength => 50); print qq| <html> <head> <title>Page Title</title> </head> <body bgcolor="#FFFFFF"> <b>Page Title</b><p> |; if ($#errors != -1) { print '<font color="#CC0000"><b>'; print join "<br>\n", @errors; print '</b></font><p>'; } print qq| <form method="post" action="$ENV{'REQUEST_URI'}"> <input type="hidden" name="submitted" value="1"> $forms{'myfield'} <input type="submit" value="Submit"> </form> </body> </html> |;