CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Submit Forms with PERL

 



Stanislav5000
New User

Mar 28, 2007, 2:28 PM

Post #1 of 3 (1976 views)
Submit Forms with PERL Can't Post

I am trying to enumerate and populate input fields in order to perform input validation testing on several sites. The sites all use a variant of firstname, Firstname, Fname, fname...you get the picture. Could you take a look at my logic below and see if there is a better way to do this? My code looks like S.

#!/usr/bin/perl
use WWW::Mechanize ;

#Prepopulated Information
my $fname="Test";
my $lname="User";
my $address="1234 Example Street";
my $city="New York";
my $state="New York";
my $zip="10010";
my $phone="2135555555";

#Create new WWW::Mechanize object
my $mech = WWW::Mechanize->new ;

#Fetch URL or Die Tryin'
$mech ->get("http://your.url/") ;
die $mech ->res->status_line unless $mech ->success ;

#Return list of forms found in the last fetched page to hand off to HTML::Form
my @webforms = $mech->forms();
#Examine each form
foreach my $form (@webforms) {
my @inputfields = $form->param;
#Examine each input field
foreach my $inputfield (@inputfields) {
if($inputfield =~ /(F|f)(irst)?name/) {
$mech->set_fields( $inputfield => $fname);
}
if($inputfield =~ /(L|l(ast)?name/) {
$mech->set_fields( $inputfield => $lname);
}
if($inputfield =~ /(A|a)ddress[123]?/) {
$mech->set_fields( $inputfield => $address);
}
if($inputfield =~ /(C|c)ity//) {
$mech->set_fields( $inputfield => $city);
}
if($inputfield =~ /(S|s)tate//) {
$mech->set_fields( $inputfield => $state);
}
if($inputfield =~ /(Z|z)ip//) {
$mech->set_fields( $inputfield => $zip);
}
if($inputfield =~ /(P|p)hone//) {
$mech->set_fields( $inputfield => $phone);
}
# Submit Completed Form or Die Tryin'
$mech ->submit ;
die $mech ->res->status_line unless $mech ->success ;
# If the form sends you somewhere, you can catch it :
my $new_url = $mech ->response->request->uri->as_string ;
}
}


KevinR
Veteran


Mar 28, 2007, 3:06 PM

Post #2 of 3 (1974 views)
Re: [Stanislav5000] Submit Forms with PERL [In reply to] Can't Post

are you saying the code does not work or just want general coments?

Close/delete the other thread in the Advanced forum.
-------------------------------------------------


Stanislav5000
New User

Mar 28, 2007, 3:11 PM

Post #3 of 3 (1973 views)
Re: [KevinR] Submit Forms with PERL [In reply to] Can't Post

I have yet to test it out (limited access from 8-5...you know the deal), and it's no good if it don't work. :)

General comments would be good too, ways to make it more efficient, smaller, easier.

Thanks!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives