Welcome Guest, Not a member yet? Register   Sign In
Validation and Private Callback Problem
#1

[eluser]mTuran[/eluser]
If i use validation callback as a private function which is _username_check, validation message convert to "Unable to access an error message corresponding to your field name.". If i convert validation callback to public everythings is ok but i have to use it as private function thanks.

Code:
$this->form_validation->set_rules('i_username2', 'lang:username', 'trim|required|min_length[4]|max_length[12]|xss_clean|callback__username_check');

Code:
function _username_check($username)
        {
            if (!$this->user->is_username_available($username))
            {
                $this->form_validation->set_message('username_check', $this->lang->line('not_available_resource'));
                return FALSE;
            }
            
            if(preg_match('/[^A-Za-z0-9_$]/', $username))
            {
                $this->form_validation->set_message('username_check', $this->lang->line('valid_username'));
                return FALSE;
            }
            
            return TRUE;
        }
#2

[eluser]Thorpe Obazee[/eluser]
[quote author="mTuran" date="1242897527"]If i use validation callback as a private function which is _username_check, validation message convert to "Unable to access an error message corresponding to your field name.". If i convert validation callback to public everythings is ok but i have to use it as private function thanks.

Code:
$this->form_validation->set_rules('i_username2', 'lang:username', 'trim|required|min_length[4]|max_length[12]|xss_clean|callback__username_check');

Code:
function _username_check($username)
        {
            if (!$this->user->is_username_available($username))
            {
                $this->form_validation->set_message('username_check', $this->lang->line('not_available_resource'));
                return FALSE;
            }
            
            if(preg_match('/[^A-Za-z0-9_$]/', $username))
            {
                $this->form_validation->set_message('username_check', $this->lang->line('valid_username'));
                return FALSE;
            }
            
            return TRUE;
        }
[/quote]

use
Code:
$this->form_validation->set_message('_username_check', $this->lang->line('valid_username'));
Code:
$this->form_validation->set_message('_username_check', $this->lang->line('not_available_resource'));
#3

[eluser]TheFuzzy0ne[/eluser]
Basically, the first parameter of the set_message method must be the exact name of the containing method, in your case, it starts with an underscore.
#4

[eluser]mTuran[/eluser]
oh you're right, i have miss out. Thanks




Theme © iAndrew 2016 - Forum software by © MyBB