Codeigniter form validation multiple callbacks

2019-07-17 19:50发布

问题:

I tried to do the following:

$this->form_validation->set_rules('username', 'lang:login_username', 'callback_login_check');
$this->form_validation->set_rules('username', 'lang:login_username', 'callback_employee_location_check');

I wouldn't get a valuation error, but this condition was always TRUE:

if($this->form_validation->run() == FALSE)

If I change the above 2 lines to:

$this->form_validation->set_rules('username', 'lang:login_username', 'callback_login_check|callback_employee_location_check');

Then it works as expected. Why can't I use the first form? Does the second one overwrite the first and the login check never gets called?

回答1:

Like you said, when you combine both callbacks inside the set_rules() it works. This is correct. If you enter them in seperatly they overwrite one another. All rules for the form input need to be in the same set_rules() method.