user4419336
user4419336

Reputation:

Display a separate error message

When the user tries to login with out filling in any information I would like to display message You have missing input Username or Password.

Currently the validation method i use only displays error if username or password does not match database records.

How can I use both?

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;
}

Upvotes: 3

Views: 75

Answers (2)

squiroid
squiroid

Reputation: 14037

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:-But it's better to handel such errors as client side with javascript because it may increase the load on server :-)

Upvotes: 1

user1717828
user1717828

Reputation: 7223

Maybe try breaking up the if condition into two conditions?

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;
}

Upvotes: 1

Related Questions