Magento Resource | E-Commerce Generation Explorer

May/10

5

How to add Magento form validation on custom form

Here is an example for how to add magento form validation to a custom form:

1
2
3
4
5
6
7
8
9
10
<form action="samepage.php" method="post" id="form_to_validate">
<input id="name" name="name" type="text" class="input-text required-entry"/>
<input id="email" name="email" type="text"  class="input-text required-entry validate-email"/>
</form>
 
<script type="text/javascript">
//< ![CDATA[
var form_to_validate = new VarienForm('form_to_validate',true);
//]]>
</script>

Notes:
– For the form to be validate you need to add the appropriate classes to your input fields.
You will notice all of the input fields have one common class name, required-entry.
To find available class names, try going to One page checkout page, where you have checkout form, then simply view source and look for class names next to input, radio select and other fields.
– Also you must add the Javascript code at the bottom of your custom form. It is quite important!

· ·

3 comments

  • Star Carlton · 24/03/2011 at 22:09

    Good info – thanks

  • Imran · 03/08/2011 at 06:45

    Hi! can you tell me how can take the users professional email id as input & not to allow the users of other domain…..
    Suppose say I have created a online store for a particular company & the employees of that particular company can only register into my online store with there Professional mail id how can i do this????

  • Chitra H · 12/10/2011 at 13:13

    It Worked.
    Thank you.

Leave a Reply

<<

>>

Theme Design by devolux.nh2.me