• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validation Custom MSG

#1
[eluser]MMCCQQ[/eluser]
hi!

i got some doubts. about validation Library.


this is my login function
Code:
function Login()
    {
    
$rules['username'] = "required";
$rules['password'] = "required";
    
        $this->validation->set_rules($rules);
    
     $fields['username'] = 'Username';
    $fields['password'] = 'Password';
    
    $this->validation->set_fields($fields);
        
    if ($this->validation->run() == FALSE)
    {
        $this->_run('account/login_view');
    }
    else
    {
        
         $this->db->where('username', $_POST['username']);
         $this->db->where('password', $_POST['password']);
     $query =$this->db->get('member');
     if ($query->num_rows() > 0){
        $row = $query->row();
        $data = array(
        'username' => $_POST['username'],
        'id'       => $row->id,
        'logged_in' => TRUE
        );
         $this->session->set_userdata($data);
         redirect('../home/');
    }else{
        
        $this->_run('account/login_view');
        
        
    
    }
    
     }
    }

i wanna send a Custom Msg when Username and Password dont match. how can i do this?

i added this
Code:
$this->validation->set_message('macth', 'Username and password don macth');

but dont work!

how?

#2
[eluser]kgill[/eluser]
The validation class can't be used to spit out messages in the way you're trying. It will return the error message if one of the rules fails - right now, the only check you are putting on a username is that it must be filled in. If you want to include checking that it is also correct you need to use a callback function. See the section in the user guide for the validation class for examples on how to do it.

- K


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.