How to validate form fields in magento without submitting the form

If you want to validate a form in Magento using prototype validations, if you use


  1.  myForm = new VarienForm('myform-id');
  2.  myform.submit = function () {
  3.   results=myForm.prototype.submit.bind(myForm)();

then the form will be submitted automatically if there is no error. That’s perfectly fine unless you want to do other work before submitting, for example submitting the form in an ajax request.

Instead you can do this to test


  1.  myForm = new VarienForm('myform-id');
  2.  myform.submit = function () {
  3.   results=myForm.validator.validate();

If results return true then there is no error.

3 thoughts on “How to validate form fields in magento without submitting the form

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.