CodeIgniter Forums
validation Custom MSG - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: validation Custom MSG (/thread-1896.html)

validation Custom MSG - El Forum - 07-03-2007


i got some doubts. about validation Library.

this is my login function
function Login()
$rules['username'] = "required";
$rules['password'] = "required";
     $fields['username'] = 'Username';
    $fields['password'] = 'Password';
    if ($this->validation->run() == FALSE)
         $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

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!


validation Custom MSG - El Forum - 07-03-2007

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