Easy Form Validation in magento

Magento provides some Default classes for validating form elements in frontend. We can make use of those existing
class names for our custom forms and reuse the client side validation code of Magento.
Let’s see a couple of examples from magento source code

1. Adding the required class to any field label will give the asterisk to be appear in red color indicating it is the mandatory field

2. If you want to make a field mandatory just add required-entry class in the input tag as shown below

3. If you want to validate the field value entered by the user there is a seperate class available. This type of classes will be used when you have fields such as
email, telephone etc. To validate an email field use validate-email class in your input tag.

4. To validate a password field use validate-password which will force the users to enter 6 or more characters .

5. To Check Password Confirmation use validate-cpassword

6. Other classes available in magento for validating various fields.

If you are familiar with Prototype Javascript framework you can even add your own validate class to the js framework.

7. And finally we need to pass the form id to the javascript to make it work

The Validation will look as shown below

Compatability :- Magento 1.3,1.4,1.5

Leave a Comment

Your email address will not be published. Required fields are marked *

twelve − eight =