Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

1 Answers

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 :-)

like image 54
squiroid Avatar answered May 05 '26 08:05

squiroid