Welcome Guest, Not a member yet? Register   Sign In
Login Form Error question
#1

[eluser]R_Nelson[/eluser]
I have a simple Login.php
Code:
<fieldset>
    <legend>Personal Information</legend>
    <ul class="errors">
        &lt;?php
        $this->form_validation->set_error_delimiters('<li>', '</li>');
        echo validation_errors(); ?&gt;
    </ul>
    &lt;?php
        
        echo form_open('user/validate_login');
        echo '<label>Username</label><br>';
        echo form_input('username','');
        echo '<label>Password</label>';
        echo form_password('password','');
        echo form_submit('submit','Login');
        echo anchor('user/register','Register');
    ?&gt;
</fieldset>

the function Validate_login
Code:
function validate_login()
    {
        $this->load->model('user_model');
        $this->form_validation->set_rules('username', 'Username', 'trim|required');
        $this->form_validation->set_rules('password', 'Password', 'trim|required');
        if($this->form_validation->run() == FALSE)
        {
            $this->index();    
        }else{
            $query = $this->user_model->validate();
            if($query) // if true
            {            
                redirect('home');
            }else{
                $this->form_validation->set_message('','User Name & Password do not Match');            
                $this->index();
            }
        }        
        
    }

and the User_model
Code:
function validate()
    {
        $this->db->where('username',$this->input->post('username'));
        $this->db->where('password',md5($this->input->post('password')));
        $query = $this->db->get('user');
        
        if($query->num_rows == 1)
        {
            foreach ($query->result() as $row)
            {                                
                $data = array(
                'username' => $this->input->post('username'),
                'id' => $row->id,
                'name' => $row->first_name.' '.$row->last_name,
                'user_level' => $row->user_level,                    
                'is_logged_in' => true
                );            
                $this->session->set_userdata($data);
            }    
            return true;
        }else{
            return false;
        }
    }
now to the question Smile the line
Code:
$this->form_validation->set_message('','User Name & Password do not Match');
in the controller i want that to display in the validation_errors on the form what do i need to put between the '' to get it to display or do i need to extend the form validation and have it do a DB check to see if they are there?


Messages In This Thread
Login Form Error question - by El Forum - 03-28-2011, 11:22 PM
Login Form Error question - by El Forum - 03-29-2011, 06:32 AM
Login Form Error question - by El Forum - 03-29-2011, 08:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB