当用户尝试登录而没有填写任何我想要显示的信息时你输入的用户名或密码丢失了。
目前我使用的验证方法仅在用户名或密码与数据库记录不匹配时显示错误。
我如何同时使用两者?
public function validate() {
$this->load->library('user');
$username = $this->input->post('username');
$password = $this->input->post('password');
if (!isset($username) || !isset($password) || !$this->user->login($username, $password)) {
$this->error['warning'] = 'The login information is incorrect!';
}
return !$this->error;
}
答案 0 :(得分:1)
也许尝试将if条件分解为两个条件?
public function validate() {
$this->load->library('user');
$username = $this->input->post('username');
$password = $this->input->post('password');
if (!isset($username) || !isset($password)){
$this->error['warning'] = 'You have missing input Username or Password';
}elseif(!$this->user->login($username, $password)) {
$this->error['warning'] = 'The login information is incorrect!';
}
return !$this->error;
}
答案 1 :(得分:1)
public function validate() {
$this->load->library('user');
$username = $this->input->post('username');
$password = $this->input->post('password');
if($username!='' && $password!='' ){
if (!isset($username) || !isset($password) || !$this->user->login($username, $password)) {
$this->error['warning'] = 'The login information is incorrect!';
}
}else{
$this->error['warning'] = 'Information incorrect!';
}
return !$this->error;
}
Ps: - 但是最好用javascript来处理客户端这样的错误,因为它可能会增加服务器上的负载: - )