aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Bypassing form validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Bypassing form validation" Watch "Bypassing form validation" New topic
Author

Bypassing form validation

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Hi,

I have a form that has validation on the textfields.The validation methods run with the submit's onclick event...
But now I have noticed that if a user presses enter,the form will be submitted without any validation being performed...
What can I do about this??


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
The validation should be run in an "onSubmit" handler of the form itself. Then it gets called no matter how the form is submitted.

You probably know this, but make sure to repeat any validations on the server. You can't rely on JavaScript code being run on the client.


Ping & DNS - my free Android networking tools app
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Okay here is the problem:


This works fine when the user clicks submit BUT if the user presses enter:
-the validate function will run and return false but the data is already posted!!

Also we can rely on javascript alone because the system is used by call-centre operators in the company
ie.they all have javascript enabled in their browsers
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
You need to write " onsubmit="return validate()" " in order for the return value to be used for stopping the form submission.
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Thanks a million!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bypassing form validation