EllisLab text mark
Advanced Search
     
validation Custom MSG
Posted: 03 July 2007 04:35 PM   [ Ignore ]
Joined: 2007-05-20
70 posts

hi!

i got some doubts. about validation Library.


this is my login function

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

$this->validation->set_message('macth''Username and password don macth'); 

but dont work!

how?

 
Posted: 03 July 2007 05:09 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2006-11-08
231 posts

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