Cjax Framework


Validate Plugin

This Plugins uses Jquery and Jquery.validate plugin to dynamically add validation functionality to your forms through CJAX Api.

Important:  You MUST load Jquery on the page for this plugin to work. You do not need to load jquery.validate plugin, it is loaded automatically if not found (Cjax 5.1+).

Features:

Plugin Usage

Defining Rules

Rules are defined in an array and take exactly the same format they take in the original jquery.validate plugin. You may also specify messages that goes with each rule.
Enter an field entry to for each field you which to validate. Each entry takes the field's "name" not the id.

<?php 

$rules 
= array(
    
'rules' => array(
        
'a[name]' => array(
            
'required' => true,
            
'minlength'  => 5,
        ),
        
'a[last_name]' => array(
            
'required' => true,
            
'minlength'  => 5,
        ),
        
'a[email]' => array(
            
'required' => true,
            
'email' => true  //in this demo is set to false to make it faster but it works.
        
)
    ),
    
'messages' => array(
        
'a[name]' => array(
            
'required' => 'Please enter your name',
        ),
        
'a[last_name]' => array(
            
'required' => 'Enter your last name',
        ),
        
'a[email]' => array(
            
'required' => 'Email is required',
        )
        
    )
);

?>

Parameters

Validate plugin takes the following parameters

Variable Required Type Options Description
$button_id Yes String May be a submit button, image or any element. Button Id which you click on to submit the form. Button MUST be inside a form.
$post_url Yes String ajax.php?controller/action Url which the form will be posted to if all fields are valid.
$rules Yes Array rules, messages, and others. Rules to validate the form.
<?php 

$validate 
$ajax->validate('btn_saveForm''ajax.php?send_form/validate'$rules);

?>

Additional Rules

You may add addional rules to your already defined rules.

<?php 

$rule  
= array(
    
'required' => true//no custom message
    
'minlength'=> array( ,'Minimum length is 2!'//with custom message
);
// field name, rule
$validate->rule('a[state]',$rule);

?>

Additional Resources:

Demo

Test validation..

Submit Form

Send any form data through ajax...

Previous Topic:  Previous Class    ·   Top of Page   ·   Demos Home   ·  

CodeIgniter  ·  Copyright © 2006 - 2012  ·  Cjax