One of the coolest things in Magento is a form validation, and the way how it’s done. Magento uses Prototype library (which, personlay, I’m not a big fan of) to manage form validation. All you need to do when writing custom form is to assign a valid class names to your input fields. Here is an example of how your custom form might look in order to get use of automatic form validation.
01.<form name="<em><strong>my-custom-form</strong>" id="my-custom-form" action="" method="post">02.03.<label for="firstname">< ?php echo $this->__('First name') ?> <span>*</span></label>04.<input id="firstname" name="firstname" />05.06.<label for="lastname">< ?php echo $this->__('Last name') ?> <span>*</span></label>07.<input id="lastname" name="lastname" />08.09.<label for="useremail">< ?php echo $this->__('Email') ?> <span>*</span></label>10.<input type="text" name="useremail" id="useremail" />11.12.<input type="submit" name="submit" value="<?php echo $this-/>__('Submit') ?>" />13.14.</form>< ?php /* END OF my-custom-form */?>15.16.<script type="text/javascript">17.//< ![CDATA[18.var customForm = new VarienForm('<em><strong>my-custom-form</strong>');19.//]]>20.</script>You will notice all of the input fields have one common class name, required-entry. I’m not gonna go over all of the available class names here. 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.
Most important thing besides assigning class names is that little piece of JavaScript below the form. Remember to pass form id into the new VarienForm object.
Basically thats it. Constructing the form this way, automaticaly makes your form reuse already existing validation code, the one that the rest of the shop is using.
Source: http://inchoo.net/ecommerce/magento/out-of-the-box-form-validation-in-magento/


