Magento Resource | E-Commerce Generation Explorer

Archive for May 2010

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!

· ·

Theme Design by devolux.nh2.me