Welcome Guest, Not a member yet? Register   Sign In
MY_validation: Unable to access an error message corresponding to your field name.
#1

[eluser]Chris Newton[/eluser]
So, I'm having a little trouble using MY_validation... and I've used it before, so I'm not sure what's going on here. Everytime I try to access a method in a model using MY_validation syntax, I get the "Unable to access an error message corresponding to your field name" message, and thusfar I've been unable to figure out why.

In the login_page controller, I call the callback_users_model->check_email_exists callback. I've checked, and it's being called.

One thing to note: according to Wiredesignz, passing "$this" during the $this->validation->run() method is optional, but in my case, if I don't pass $this, I get an error condition "Missing argument 1 for MY_Validation::run(),"

Any ideas? I can't figure out what about this usage of MY_Validation would cause this, when previous uses have worked fine.

Controller Code.
Code:
function login()
    {  
    
        $this->load->library('validation');
        $this->load->library('encrypt');
        $this->load->model('sessions_model');
        $this->load->model('flashdata_model');
        $this->load->model('users_model');
        $this->load->helper(array('form','cookie','html','url'));
        // The line in question
        $rules['login_box_username']    =    'trim|required|min_length[5]|max_length[300]|htmlentities|callback_users_model->check_email_exists[login_box_username]';
        $rules['login_box_password']    =     'trim|required|min_length[5]|max_length[300]|htmlentities';
        $rules['login_box_remember']    =    'trim';        
        $this->validation->set_rules($rules);
        
         $fields['login_box_username']    =    'email address';
        $fields['login_box_password']    =    'password';
        $fields['login_box_remember']    =    'remember me';  
        $this->validation->set_fields($fields);

        if ($this->validation->run($this)===FALSE)
        {
            $this->load->view('view_login');
        }
        else
        {  
            $email               =    $this->input->post('login_box_username');
            $password        =    $this->input->post('login_box_password');  
              $success        =    $this->bn_auth->try_login(array('email_address'=>$email),$password);
            if ($success)
            {    
                $this->sessions_model->get_id();
                $this->sessions_model->db_set('user_id',$this->sessions_model->get('user_id'));  
                $this->flashdata_model->set('success_message', 'Login was successful');
                if (isset($location))
                {
                    redirect($location,'refresh');
                }
                else
                {
                    redirect(index_page(),'refresh');
                }
            }
            else
            {
                $this->flashdata_model->set('error_message', 'Your password was not recognized, please try logging in again');
                redirect('login_page/login','refresh');
            }
           }
    }

Model Code
Code:
public function check_email_exists($email,$field)
    {
        $this->load->library('validation');
        if ($this->_check_exists($email,'email_address'))
        {
            return TRUE;
        }
        else
        {
            $classname=get_class($this);
            $this->validation->set_message($classname.'->check_email_exists', "%s {$email} is not registered, please try another email address");
            return FALSE;
        }
    }
#2

[eluser]Chris Newton[/eluser]
If I add a message to the validation_lang file... this works. But I don't seem to have luck using the set_message method.
#3

[eluser]Chris Newton[/eluser]
Figured it out. In the past this hasn't mattered... (I know because I have some other working sites that don't exhibit this behavior) but in this case I need to use:

Code:
$classname=strtolower(get_class($this));
rather than
Code:
$classname=get_class($this);

the $classname was being set Users_model, which is not being recognized in the same manner as 'users_model'.
#4

[eluser]rpl oye[/eluser]
on your call back, make sure that your set_message is setting the correct call back.
mine was
function recaptcha_check(){
...
$this->form_validation->set_message('username_check', 'Invalid '.$resp->error);
...

this was generating error

then i changed it to
$this->form_validation->set_message('recaptcha_check', 'Invalid '.$resp->error);

then it s working alright
#5

[eluser]gregorius[/eluser]
rpl oye
Thanks you are right, it help




Theme © iAndrew 2016 - Forum software by © MyBB