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


myForm = new VarienForm('myform-id'); myform.submit = function () { 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


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

If results return true then there is no error.