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

Hi Monks, I am new in Perl and I am encountering a problem with submitting my form.
The form has a text field for both username and password. And instead of having button type="submit", the form has this span id="submitButton" with  onkeypress and onclick.
Is there a way on clicking or submitting the form using the span that is in the form? Any advice or suggestions?
Thanks in advance. :)

Replies are listed 'Best First'.
Re: Submitting Forms for .NET Sites Problem
by Gangabass (Vicar) on May 08, 2015 at 03:37 UTC
    First you need to understand will your form work with Javascript disabled or not. I recommend to disable Javascript in your browser and submit your form after that. If the form will work then all you need is just submit your data with WWW::Mechanize:
    $mech->submit_form( with_fields => { login => "somelogin", password => "somepassword", }, );
    If you can't submit your data from the browser with Javascript disabled you can either emulate same POST request in your code or you can use browser automation (like WWW::Mechanize::PhantomJS)
Re: Submitting Forms for .NET Sites Problem
by ww (Archbishop) on May 08, 2015 at 03:29 UTC

    With all the goodwill in the world, please heed the advice in On asking for help, How do I post a question effectively? and I know what I mean. Why don't you?. Please also read about the local markup codes at Markup in the Monastery.

    Specifically we (well, /me anyway) need to see the code to help you:

    1. The span id="submit button" very likely applies a particular style to the material it encloses, up to </span>. The style is likely defined in a separate file -- somename.css, altho it may be in the html.
    2. Without seeing the code, I can't guess exactly what the javascript directives onclick and onkeypress invoke... though looking thru your code is apt to show that one of them functions in place ofthe missing submit button.

    Knowing more about the code will help us arrive at reasonable ansers for your question... as well some indication of your ability to read html and perl code, since your language at least raises the possibility that you are not the author of either.

      Hi,
      Please see below code snippet for the HTML form for your reference.

      <div id="loginArea"> <div id="loginMessage" class="groupMargin">Sign in with your a +ccount</div> <form method="post" id="Login" autocomplete="off" novalidate=" +novalidate" onkeypress="if (event &amp;&amp; event.keyCode == 13) Log +in.submitLoginRequest();" action=""> <div id="formsAuthenticationArea"> <div id="userNameArea"> <input id="userNameInput" name="UserName" type="em +ail" value="" tabindex="1" class="text fullWidth" spellcheck="false" +placeholder="Username" autocomplete="off"> </div> <div id="passwordArea"> <input id="passwordInput" name="Password" type="p +assword" tabindex="2" class="text fullWidth" placeholder="Password" a +utocomplete="off"> </div> <div id="kmsiArea" style="display:none"> <input type="checkbox" name="Kmsi" id="kmsiInput" +value="true" tabindex="3"> <label for="kmsiInput">Keep me signed in</label> </div> <div id="submissionArea" class="submitMargin"> <span id="submitButton" class="submit" tabindex="4 +" onkeypress="if (event &amp;&amp; event.keyCode == 32) Login.submitL +oginRequest();" onclick="return Login.submitLoginRequest();">Sign in< +/span> </div> </div> </form> </div>

      Yes, the login site is not mine, but I wanted to submit the form with the credentials that I have for me to be able to go through to the site I intended to go.
      We used WWW::Mechanize for this using the code snippet below:
      my $mech = WWW::Mechanize->new(); $response = $mech->get($URL); $mech->submit_form( fields => { UserName => $username, Password => $password, },);

      but I am unable to go through the login site. I suspect that it is because of the JavaScript that is in the form and or the span.
      Any suggestions or advice on how to submit the form?

      Your help is highly appreciated. Thank you in advance.
        Can you post Login.submitLoginRequest() definition?