CodeIgniter Forums
Validation function refusing to callback. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Validation function refusing to callback. (/showthread.php?tid=22647)



Validation function refusing to callback. - El Forum - 09-16-2009

[eluser]JasonS[/eluser]
Can someone have a quick look at this and tell me where I am going wrong.

The Validation Rules
Code:
$this->form_validation->set_rules('username', 'Username', 'required|alpha_dash|max_length[40]|callback_unique_username');

The Callback - Modified to fail all the time.
Code:
public function unique_username($str)
{
    //if ($this->register_model->unique_username($str))
    //{
        $this->form_validation->set_message('unique_username', 'The username selected is already in use.');
        return FALSE;
    //}
            
    //return true;
}

When I run the form. The callback isn't called.


Validation function refusing to callback. - El Forum - 09-16-2009

[eluser]JasonS[/eluser]
I have investigated further. Going into CI.

The callback is failing because of these lines in the form_validation library.

Code:
if ( ! method_exists($this->CI, $rule))
{        
    continue;
}

Basically, it cannot find the function. Is this a bug?


Validation function refusing to callback. - El Forum - 09-16-2009

[eluser]JasonS[/eluser]
Gah, something to do with the use of modules.. will look into it further


Validation function refusing to callback. - El Forum - 09-16-2009

[eluser]BrianDHall[/eluser]
Your callback function needs to be in the same controller as where you are calling it, and CI does not require it be a public function (though I don't know that it minds...or knows, either way). If you are trying to define the callback function in a library, module, or another controller it won't work. You might be able to define it in a helper though.

If that doesn't work then someone else is wrong.


Validation function refusing to callback. - El Forum - 09-16-2009

[eluser]JasonS[/eluser]
I have tried to define the callback in a helper. No joy.

Does this happen with matchbox as well as modular extensions?

I was planning for my application to be primarily based on modules. Is there a work around for this?


Validation function refusing to callback. - El Forum - 09-16-2009

[eluser]JasonS[/eluser]
Found the solution.

http://ellislab.com/forums/viewthread/92212/P90/#578755