Welcome Guest, Not a member yet? Register   Sign In
Showing form validation errors through logic
#1

[eluser]Rein Van Oyen[/eluser]
Hello all,


I'm fairly new to CodeIgniter. I like it so far, but sometimes I run into small problems.

I'm making a simple login system to wrap around my admin-systems. I'm using the form validation class to show an error on top of the page when a form doesn't validate. How can I manually set an error. Even if the rules for the form were passed?

This is the code in my controller;

Code:
$this->form_validation->set_rules('username', 'gebruikersnaam', 'required');
$this->form_validation->set_rules('password', 'wachtwoord', 'required');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('admin/login');
        }
        else
        {
            if($this->input->post('remember')){
                $auth = $this->user->authenticate($this->input->post('username'), $this->input->post('password'), true);
            }
            else
            {
                $auth = $this->user->authenticate($this->input->post('username'), $this->input->post('password'), false);
            }
            
            if($auth){
                redirect('admin/main');
            }
            else
            {
                $this->load->view('admin/login');
            }
            
        }

Would something like below be possible?

Code:
if($auth){
    redirect('admin/main');
}
else
{
    $this->form_validation->show_error('Password and username incorrect');
    $this->load->view('admin/login');
}

Edit: Sorry for posting this in the wrong forums
#2

[eluser]Rein Van Oyen[/eluser]
Anyone?
#3

[eluser]kirkaracha[/eluser]
How to add your own custom errors to the form validation class




Theme © iAndrew 2016 - Forum software by © MyBB