Welcome Guest, Not a member yet? Register   Sign In
Login solution
#1

[eluser]Alix.G[/eluser]
Hi,

I'm creating a simple user login form using codeigniter validation form class.

Here is my form:
Code:
&lt;?php echo validation_errors('<p class="error">', '</p>'); ?&gt;
    
&lt;?php echo form_open("admin/validate_login"); ?&gt;
    
<ul>
        
    <li>
        &lt;?php echo form_label('Username: ', 'au_username').form_input("au_username", "Username", 'class="in_text"'); ?&gt;
    </li>
        
    <li>
        &lt;?php echo form_label('Password: ', 'au_password').form_password("au_password", "Password", 'class="in_text"'); ?&gt;
    </li>
        
    <li>
        &lt;?php echo form_submit("submit", "Submit", 'class="in_submit"'); ?&gt;
    </li>
        
</ul>
    
&lt;?php echo form_close(); ?&gt;

And here is my controller
Code:
function validate_login()
{
    $this->form_validation->set_rules('au_username', 'username', 'trim|reuired');
    $this->form_validation->set_rules('au_password', 'password', 'trim|required|md5');
    
    if($this->form_validation->run() == TRUE)
    {
        $query = $this->admin_user_model->login();
            
        if($query)
        {
            $this->session->set_userdata('logged', true);
            $this->session->set_userdata('au_username', $this->input->post('au_username'));
        }
            
        redirect('admin');
    }
    else
    {
        $data['content_file'] = "login";
        $data['page_title'] = "Login";
            
        //load view
        $this->load->view('admin/template', $data);
    }
        
}

The associated model:
Code:
function login()
{
    $this->db->where('au_username', $this->input->post('au_username'));
    $this->db->where('au_password', $this->input->post('au_password'));
        
    $q = $this->db->get('admin_user');
        
    if($q->num_rows() == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
        
}

Now here is my problem, I would like to know what would be the best way to have a callback when username/password verification failed.

Thank you
#2

[eluser]Unknown[/eluser]
I would say that you need to create a custom callback to do the username validation.

http://ellislab.com/codeigniter/user-gui...#callbacks
#3

[eluser]jeffpeck[/eluser]
Code:
$this->form_validation->set_rules('au_username', 'username', 'trim|reuired');


That should be "required"... not "reuired". Codeigniter does not seem to give errors if it cannot find the function, so that should save you some trouble.
#4

[eluser]Alix.G[/eluser]
lol, I figured it out earlier but thanks anyway!




Theme © iAndrew 2016 - Forum software by © MyBB