Hi all,

I am using codeigniter freamwork. The following is a list of all the native rules that are available to use:

required No Returns FALSE if the form element is empty.
matches Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item]
is_unique Yes Returns FALSE if the form element is not unique to the table and field name in the parameter. is_unique[table.field]

what I need is definig my own native rule. I tried to find where codeigniter has defined above rules. but I coudnt find it.

If anybody can plz help me to find the above native rules where they are defined. or help me to define native methode.


thanks in advance.........

You can extend the Form_validation library which is in System/Libraries or you can use callbacks: http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks

To extend an existent library check at the end of this page: http://codeigniter.com/user_guide/general/creating_libraries.html

Also if you create a callback function set that public and if you don't want to be accessible from the url then place an underscore before the name of the function, example:

# if private or protected it won't work
public function _confirm($y)
{
        if($y == 'yes')
        {
            return true;
        }
        else
        {
            # without error message you get a notice from CI.
            $this->form_validation->set_message('_confirm', 'Value of %s is not valid.');
            return false;
        }
}

In your rule then you will write:

$this->form_validation->set_rules('confirm', 'confirm checkbox', 'trim|required|exact_length[3]|xss_clean|callback__confirm');

bye :)