I have a standard form which logs my users into a separate site.
<form action="http://www.url.com/" name="loginform" method="post">
<input type="hidden" name="pg" value="/index.cfm">
<input type="hidden" name="login" id="login" value="loginname"><br>
<input type="hidden" name="pwd" id="pwd" value="mypass">
<input type="submit" value="OK">
</form>
Using WWW::Mechanize I am able to insert username, password and submit,logging in with no problems. The slight twist is that I don't want to print the page, but actually go to the website in question. So ideally I would provide a link to the login script, autofill out the form and submit, and the user will be logged in to the site.
Of course I can pre-fill the form and the user simply needs to click submit, but I want to remove that step.
The site does not accept 'get' actions so it has to be 'post'.
To clarify, I have used the following code to log in, but instead of printing the page within the script, I want to end up on the landing page (after successful log in) on the other site!
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI ':standard';
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $url = "http://www.url.com/";
$mech->get($url);
my $result = $mech->submit_form(
form_name => 'loginform', #name of the form
#instead of form name you can specify
#form_number => 1
fields =>
{
login => 'loginname', # name of the input field and value
pwd => 'mypass',
}
,button => 'loginconsole_button' #name of the submit button
);
print "Content-type: text/html\n\n";
print $result->content();