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?
#2

[eluser]Suhas nazir[/eluser]
Hey

$this->form_validation->set_message is something that deals with setting of message based on form validation ,And in your case this is not a form validation error right.So i think the best way is to change the status of a variable based on affected rows ,and send it to view and where u need to check the status and put the needed error message.......
#3

[eluser]R_Nelson[/eluser]
I would like to just ad the error to the form validation output so i don't have to put in an if statement and all that. I'm gonna go look at the library and see how it saves it and see if i can just add to the array




Theme © iAndrew 2016 - Forum software by © MyBB