Skip to content Skip to sidebar Skip to footer

Codeigniter Simple Login Validation Not Working

Im a beginner in web programming, so please bear with me. I tried to create a login system that will do those validation : The email is required and must be valid The password is

Solution 1:

for checking each field validation errors inside your view do write like this after each input which you are going to validate it.

<inputtype='text'name='id_no'id='id_no' /><?=form_error('id_no')?>

Solution 2:

It is better to handle this in Controller:

Controller:

functionlogin()
{
    // Set the default value$data['error'] = '';

    $this->form_validation->set_rules('txt_email', 'Email', 'required|valid_email');
    $this->form_validation->set_rules('txt_password', 'Password', 'required');

    if($this->form_validation->run() !== FALSE)
    {
        $log_in = $this->umat_m->log_in(
            $this->input->post('txt_email'),
            $this->input->post('txt_password')
        );

        if($log_in !== FALSE)
        {
            $_SESSION['username'] = $this->input->post('txt_email');
            redirect('backend/umat/index');
        } else {
            // Set your error message$data['error'] = 'Wrong Username/Password';
        }
    } else {
        // Set the validation errors$data['error'] = validation_errors();
    }

    $this->load->view('backend/login_v', $data);
}

View:

<?phpif ($error): ?><spanclass="label label-important"><?phpecho$error; ?></span><?phpendif?>

Post a Comment for "Codeigniter Simple Login Validation Not Working"