Search code examples
codeignitercallbackvalidationcodeigniter-2validationrules

In Codeigniter, how to pass a third parameter to a callback (form validation)?


I am currently using the Form Validation class (on Codeigniter) and setting rules.

It works like this with two parameters (codeigniter.com/user_guide/libraries/form_validation.html):

$this->form_validation->set_rules('username', 'Username', 'callback_test[abc]');

But what about a third parameter? And a fourth...? Is it possible?


Solution

  • It is not official but works

    Split the parameter by ','

    $this->form_validation->set_rules('article_big_image','Gambar Besar','callback_check_picture[article_big_image,edit]');
    
    function check_picture($image,$param){
        $param = preg_split('/,/', $param);
        $field = $param[0];
        $action = $param[1];
        echo $field.$action;
    }