title: perl login and submit with WWW::Mechanize
body: <p>I have a standard form which logs my users into a separate site.</p>
  
  <pre><code>&lt;form action="http://www.url.com/" name="loginform" method="post"&gt;
  &lt;input type="hidden" name="pg" value="/index.cfm"&gt;
  &lt;input type="hidden" name="login" id="login" value="loginname"&gt;&lt;br&gt;
  &lt;input type="hidden" name="pwd" id="pwd" value="mypass"&gt;
  &lt;input type="submit" value="OK"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>Of course I can pre-fill the form and the user simply needs to click submit, but I want to remove that step.</p>
  
  <p>The site does not accept 'get' actions so it has to be 'post'.</p>
  
  <p>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!</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
  use CGI ':standard';
  use WWW::Mechanize;
  my $mech = WWW::Mechanize-&gt;new();
  
  my $url = "http://www.url.com/";
  
  $mech-&gt;get($url);
  
  
  my $result = $mech-&gt;submit_form(
  form_name =&gt; 'loginform', #name of the form
  #instead of form name you can specify
  #form_number =&gt; 1
  fields      =&gt;
  {
   login    =&gt; 'loginname', # name of the input field and value
   pwd    =&gt; 'mypass',
  }
  ,button    =&gt; 'loginconsole_button' #name of the submit button
  );
  
  print "Content-type: text/html\n\n";
   print $result-&gt;content();
  </code></pre>