我试图弄清楚为什么当我的数据库中与我的用户名或电子邮件地址匹配时它不报告验证错误。
它仍然将此显示为正确的帖子参数。在将焦点移开时,它确实会执行两个不同的发布请求。
注册控制器:
public function is_username_available()
{
if ($this->users_model->is_username_available($this->input->post('username')))
{
return false;
}
else
{
return true;
}
}
public function is_email_available()
{
if ($this->users_model->is_email_available($this->input->post('email_address')))
{
return false;
}
else
{
return true;
}
}
注册.js
rules: {
username: {
minlength: 6,
maxlength: 12,
remote: {
type: 'post',
url: 'register/is_username_available',
data: {
'username': function() { return $('#username').val(); }
},
dataType: 'json'
}
},
email_address: {
email: true,
remote: {
type: 'post',
url: 'register/is_email_available',
data: {
'email_address': function() { return $("#email_address").val(); }
},
dataType: 'json'
}
}
用户型号:
/**
* Check if username available for registering
*
* @param string
* @return bool
*/
function is_username_available($username)
{
$this->db->select('username', FALSE);
$this->db->where('LOWER(username)=', strtolower($username));
$query = $this->db->get($this->users_table);
echo $this->db->last_query();
return $query->num_rows() == 0;
}
/**
* Check if email available for registering
*
* @param string
* @return bool
*/
function is_email_available($email)
{
$this->db->select('email', FALSE);
$this->db->where('LOWER(email)=', strtolower($email));
$query = $this->db->get($this->users_table);
return $query->num_rows() == 0;
}