Codeigniter表单验证多个回调

问题描述:

我尝试执行以下操作:

$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');

我不会收到估值错误,但这种情况始终为TRUE:

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?

就像您说的那样,当您在set_rules()中合并两个回调时,它将起作用.这是对的.如果您分别输入它们,它们将相互覆盖.表单输入的所有规则都必须使用相同的set_rules()方法.

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.