in reply to submitting nameless form using WWW::mechanize

Submit it by number instead, like the synopsis of WWW::Mechanize shows:

$mech->submit_form( form_number => 3, fields => { username => 'mungo', password => 'lost-and-alone', } );

Replies are listed 'Best First'.
Re^2: submitting nameless form using WWW::mechanize
by opensourcer (Monk) on Jun 18, 2008 at 06:52 UTC
    it's a nameless form <form> .... </form>
    i have checked for form number using $mech->forms()
    which displays nothing .
      "i have checked for form number using $mech->forms() which displays nothing."

      This might be due to JavaScript generated forms, which are really a pain in the ***. Try to look at the source through your preferred webbrowser and see what's going on there. If the form is there, without a name, indeed simply count them (and don't forget hidden forms ;-)

      --
      b10m
        The following is the code inside the html.
        <body onLoad="getSearch();getUserSettings();callonLoad();"> <form> <p>&nbsp;</p> <table width="775" border="0" align="center" cellpadding="0" cellsp +acing="0" bgcolor="#FFFFFF"> <tr> <td><img src="/userportal/pages/usermedia/inventumtest.1/images/ +top.jpg" width="775" height="111"></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding= +"0"> <tr> <td width="33%"><div align="center"><img src="/userportal/ +pages/usermedia/inventumtest.1/images/lady.jpg" width="161" height="2 +00"></div></td> <td><table width="240" height="150" border="0" align="cen +ter" cellpadding="0" cellspacing="0" background="/userportal/pages/us +ermedia/inventumtest.1/images/TableBG.jpg"> <tr> <td valign="top"><table width="100%" height="100%" bo +rder="0" cellpadding="1" cellspacing="1"> <tr> <td colspan="2" class="loginBoxMainStyle"><div a +lign="left">&nbsp;Login</div></td> </tr> <tr> <td class="loginBoxTextStyle"><div align="right" +>Service Type :</div></td> <td> <select name="type" class="loginBoxTextStyl +e"><option value="1">Check Account Details</option></select> </td> </tr> <tr> <td class="loginBoxTextStyle"><div align="right" +>Login ID : </div></td> <td><input type="text" name="username" value="" +class="loginBoxFormTextStyle"></td> </tr> <tr> <td class="loginBoxTextStyle"><div align="right" +>Password : </div></td> <td><input type="password" name="password" value +="" class="loginBoxFormTextStyle"></td> </tr> <tr> <td colspan="2" class="loginBoxTextStyle"><div a +lign="center"> <input type="checkbox" id="rememberme" name="rememberme" >Remember Me +</div></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="button" value="Login" class="loginBoxTextStyle" onclick=" +return savesettings();"/> </div></td> </tr> </table></td> </tr> </table></td> <td width="33%"><table width="100%" border="0" cellspacin +g="0" cellpadding="0"> <tr id="popup" style="display:none"> <td><table width="240" height="150" border="0" align= +"center" cellpadding="0" cellspacing="0" background="/userportal/page +s/usermedia/inventumtest.1/images/TableBG.jpg"> <tr> <td valign="top"><table width="100%" height="100%" + border="0" cellpadding="1" cellspacing="1"> <tr> <td colspan="2" class="loginBoxMainStyle"><d +iv align="left">&nbsp;Session Details </div></td> </tr> <tr> <td class="loginBoxTextStyle"><div align="ri +ght">Start Time : </div></td> <td><INPUT TYPE=TEXT NAME="start" SIZE=17 va +lue="18/06/2008 09:24:55" readonly></td> </tr> <tr> <td class="loginBoxTextStyle"><div align="ri +ght">Duration : </div></td> <td><INPUT TYPE=TEXT NAME="duration" SIZE=17 + readonly></td> </tr> <tr> <td class="loginBoxTextStyle"><div align="ri +ght">Balance :</div></td> <td><INPUT TYPE=TEXT size="17" NAME="subs" v +alue="" readonly></td> </tr> <tr> <td class="loginBoxTextStyle" colspan="2"> <b>Your Internet Session Active</b> &nbsp;&nbsp;<a href="/userportal/logout.do"> +Click Here To Logout</a></td> </tr> <tr> <td class="loginBoxTextStyle"><div align="ri +ght"></div></td> <td>&nbsp;</td> </tr> </table></td> </tr> </table></td> </tr> </table> </td> </tr> </table></td> </tr> <tr> <td><img src="/userportal/pages/usermedia/inventumtest.1/images/ +inventlogo.png" width="140" height="43"></td> </tr> <tr> <td bgcolor="#336699"><div align="center" class="loginBoxTextSty +le"><font color="#ffffff">Powered by SSG Unify <a href="http://www.in +ventum.cc"><font color="#ffffcc"> (c) Inventum Technologies Pvt. Ltd. +</font></a></font></div></td> </tr> </table> <INPUT TYPE=hidden NAME="clock"> </form>

        I have tried every number in the block (1..x) but ...
        script says: There is no form numbered 4 at autologin.pl line 45 Died at /usr/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1724.

      Every form has a number. You start counting by 1 and increment the form number whenever a new form starts. Just try it:

      $mech->form_number(3); # selects the third form on the page $mech->submit; # submits the third form
      Count, you know 1, 2, 3, 4, 5 , 6, 7, 8, 9, 10, them select the form 3rd form on the page