在编辑表单中我检查唯一的电子邮件,如果用户点击提交按钮仍然显示错误消息,因为它不是唯一的。虽然它是独特的价值 这是控制器中的验证
$this->form_validation->set_rules('email','Email','required|callback_check_email');
和回调函数
function check_email($email)
{
$return_value = $this->user_model->check_email($email);
if ($return_value)
{
$this->form_validation->set_message('check_email', 'Sorry, This email is already used by another user please select another one');
return FALSE;
}
else
{
return TRUE;
}
}
这是用户模型
function check_email($email)
{
$id=$this->session->userdata('id');
$this->db->select('Email');
$query = $this->db->get_where('users',array('id !=' => $id,'Email' => $email));
return $query->row_array();;
}
答案 0 :(得分:0)
试试这个 -
$this->form_validation->set_rules('email','Email','required|callback_check_email[email]');
答案 1 :(得分:0)
如果check_email函数仅用于验证,则应添加_作为名称前缀,以使其无法像私有函数那样进行公共访问,并且不会通过URL请求提供:
public function _check_mail($email)
使用额外_和电子邮件作为参数调用验证函数:
$this->form_validation->set_rules('email','Email','required|callback__check_email[email]');
还有一个额外_用于验证消息:
$this->form_validation->set_message('_check_email', 'Sorry, This email is already used by another user please select another one');