Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bypassing form validation

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a million!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic