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

Dacobah picture Dacobah · Jan 5, 2012 · Viewed 12.5k times · Source

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?

Answer

Andhri Hermawan Effendi picture Andhri Hermawan Effendi · May 23, 2012

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;
}