Php 在codeigniter的编辑函数中使用回调函数验证唯一值
在编辑表单中,我正在检查唯一的电子邮件,如果用户单击“提交”按钮,它仍然会显示错误消息“非唯一”。虽然它是独一无二的价值 这是控制器中的验证Php 在codeigniter的编辑函数中使用回调函数验证唯一值,php,sql,codeigniter,Php,Sql,Codeigniter,在编辑表单中,我正在检查唯一的电子邮件,如果用户单击“提交”按钮,它仍然会显示错误消息“非唯一”。虽然它是独一无二的价值 这是控制器中的验证 $this->form_validation->set_rules('email','Email','required|callback_check_email'); 以及回调函数 function check_email($email) { $return_value = $this->user_m
$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();;
}
试试这个-
$this->form_validation->set_rules('email','Email','required|callback_check_email[email]');
如果check_电子邮件功能仅用于验证,则应添加u作为名称前缀,以使其像私人功能一样无法供公共访问,并且不会通过URL请求提供:
public function _check_mail($email)
使用额外的u和电子邮件作为参数调用验证函数:
$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');