Codeigniter表单验证多个回调 [英] Codeigniter form validation multiple callbacks
本文介绍了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.
这篇关于Codeigniter表单验证多个回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文