in reply to How to login to a form which has Javascript OnSubmit method usirng Perl

hi,

what I would suggest, is that you need to remember that Javascript is doing all of its work in the user's browser. And Perl is working on the server.
what you do in this simple case... is have the submit button send the collected data to your script...

wile the user is filling in the form, you have either a monolithic Javascript function or object or lots of little functions working on the input data.

form fields have events... that you can attach these javascripts to... onBlur, onFocus, onClick on mouseOver, etc... so, let's say you want to check that the name and the password are at least filled in...:

you add a handler function which checks just that... however you will have to use logic.. and some human interface ergonomics...
so simple it is to have an annoying alert pop up... dig a little further and you can write directly into the page in an empty "div". and then finally, perhaps a global variable in Javascript... indicates whether all the tests are passed, and sure put them in the hidden fields to make url-encoded key/value pairs for your perl script to extract and perform all the real tests and send off to your data-store and finally let the user access the golden Home page of desire.

If that last bit was not clearly enough written, try to let a javascript function actually make the call as to when to set the page location to your script-url

once the perl script is satisfied... it then returns the URL for the page to which all this logging in was all about.

in short, it is time to start handing off some of the work to the new kid -- JS.

This is actually the only secret of WEB 2.0. and based on my searches on the net, PHP has taken over in most of those applications mostly because PERL is too powerful.

The other answers to this question clearly illustrate the singlemindedness and perhaps stubborness of PERL programmers, sure perl can do it all, but if the pass and login have invalid format, or illegal characters, it seems best to let the user know before he wastes the server's time with silly stuff. And you can have perl generate all of the Javascript and html/css into the login window, so detect your browser variables, write a hash and track the user with cookies: these are the power of your Perl.

In fact, since users are now running around with vast amounts of unused CPU power, have your PERL scripts send parts of huge problems out to user's javascipt engines and return the answers back to your script for futher routing and matrix processing, Turn your 1000's of clicks into a massively parallel network renderer...

...or, have I said too much?
  • Comment on Re: How to login to a form which has Javascript OnSubmit method usirng Perl

Replies are listed 'Best First'.
Re^2: How to login to a form which has Javascript OnSubmit method usirng Perl
by moritz (Cardinal) on Nov 04, 2007 at 14:57 UTC
    I think ragas wants to automate a login process with a perl client, and can't control the server side - that's why it is impossible to avoid dealing with javascript.

    All those explanations about web 2.0 , js and perl (not PERL, btw) are fine, but they don't help with the task at hand.

      I hoped that i could answer without any code snippets and yes perhaps I did extrapolate too far...
      <form method="POST" action="in(cgiurl)" name=form1 onSubmit="return Se +tPass();">

      is the basic line...

      in this case, set pass actually sets the cookie, however, if the cookie is wrong, the script won't work... lot's more could be done there... by JS... I let the perl script send the users to the templated login page... so a simple link from a public page or inline on that public page... it will work the same if you submit action to the actual address of your script. basically, your script has to deal with the info it gets... there is a data parsing function ... getdata ... called by the main() function
      if($usecgi){ use CGI; $query = new CGI; @names = $query->param; foreach $i (@names){ $in{$i} = $query->param("$i"); } } else{ # Read in text if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) { $in .= getc; } } #.... followed by more code for parsing, splitting and assigning the n +ew variables

      this sample script parses the POST data if any... here there are 2 conditions which call the login template...

      ($in{'command'} eq 'login')&&(&Login); ($in{'command'} eq '')&&(&Login); #all require password below &GetLogin; ... # passing thru Get login allows access to more program functions and a +dditional pages. the login page actually calls the next page... via h +idden form field


      I don't see his code doing any of that. I see him trying to set up the page and sending them off to the secret content without having the server do any checking via perl.
      If it successfully presents the login page, then it will finally need to pass thru the login page to the goodies behind that. for security reasons, I can see why the javascript shoul disguise the username and password and then potentially send the data either as the cookie request or via plain text... with or without the benefits of ssl.

      I previously provided the basic hint to look at Javascript and let it do what it does and allow perl to do what it does...
      in my case, setPass() does the combination of verifying that user has filled both fields and alerting if otherwise... it then creates a hash and stores the cookies locally... when setpass is satisfied, it returns true. otherwise it returns false. and the action fails. and the hidden field provides the (CGI)action "manage" which can only be reached by passing thru the GetLogin/Cookie retrieval process. and continuing to have a cookie until the session expires. Any failures should take youu back to the login screen.
      sub GetCookies{ $cookies = $ENV{'HTTP_COOKIE'}; @allcookies = split(/;\s*/,$cookies); foreach $i (@allcookies){ ($name,$value) = split(/\s*=\s*/,$i); $cookie{$name}=$value; } }


      the perl script then knows how to extract and check the cookies , and finally, it checks the retrieved against the stored password and username
      sub GetLogin{ &GetCookies; $in{'UserName'} = $cookie{'UserName'}; $in{'PassWord'} = $cookie{'PassWord'}; if(!$in{'UserName'}){ &PageOut('t_login.htm'); exit; #back where you started, though the Javascript sees that it never com +es here } else{ (($in{'UserName'} ne $username)||(($in{'PassWord'} ne $password)))&&(& +PError("Error. Invalid username or password")); #here we need to check the final results after parsing the cookie info + and retrieving matches in the db of variables... we have no choice +but to return a server error message. } }


      one might substitute a Mechanized page for a template... so on the first call to the script, you build the page, and the second call to the script, checks the returned data...

      essentially, there is a shared variable space @in{''} which need be passed between the page (javascript) and the server (perl)

      I certainly will continue to maintain that "the old way" is to ignore javascript and just continue to pass the variables back to the serverside parsing and keep returning the errors that way. (ERRORS in actual password or login are unavoidably handled this way.)
      Yes, Perfect. You have put it short and sweet. I am trying to build a perl client for automating the login process and the Javascript and server side logic is not in my control. So I am looking for alternatives.