CI自定义表单验证问题
不知道为什么,我根据手册操作自定义表单规则,但是老是提示这个public function do_update_admin()
{
//调用验证规则
$this->form_validation->set_rules('admin_user','* 原始密码','callback_username_check');
$this->form_validation->set_rules('newpass','* 新密码','required');
$this->form_validation->set_rules('renewpass','* 确认密码','required|matches');
//表单验证
if($this->form_validation->run() == FALSE)
{
$this->load->view('admin/pass.html');
}
}
public function username_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message('原始密码', '原始密码不对!');
return FALSE;
}
else
{
return TRUE;
}
}
验证后出现这个:(username_check)
$this->form_validation->set_message('原始密码', '原始密码不对!');
应该为:
$this->form_validation->set_message('username_check', '原始密码不对!')
因为你用了回调,因此得设置回调的错误信息。
参见:
表单验证-设置错误信息
http://codeigniter.org.cn/user_guide/libraries/form_validation.html#setting-error-messages wangyouworld 发表于 2017-9-15 09:47
应该为:
太感谢您了
页:
[1]