Form Validation

Navigation:  Development > Helpers > JavaScript >

Form Validation

Previous pageReturn to chapter overviewNext page

appForm is a Helper that used to submit a HTML Form. We can also add Validation and AJAX with it. See below format

 

App::Helper('JavaScript')->appForm(Element);
 
Element : Form can be a HTML Id, Class or Tag Name.

 

After attaching the HTML we can set validation rule in each input field. It's just a Class name in the tag to apply the rule. appFrom support below rules.
 

Class Name

check_notempty : Check Empty value

check_notdefault : Check Default value of a field

check_email : Check Valid email address

check_password  : Check Password

check_isnumber         : Check Numeric Value

check_alphanumeric: Check Alpha Numeric Value.

 

 
Se below example:
<form method="post" id="myform">
<ul>
  <li><input type="text" name="data[Myform][field1]" class="check_notempty" longdesc="Please enter a value" /></li>
  <li><input type="text" name="data[Myform][field1]" class="check_notdefault" longdesc="Please change default value" value="My Default"/></li>
  <li><input type="text" name="data[Myform][field1]" class="check_email" longdesc="Please enter a valid email address" /></li>
  <li><input type="submit" name="data[Myform][submit]" value="Submit" /></li>
</ul>  
</form>

<?php App::Helper('JavaScript')->appForm('#myform');?>