[eluser]DrDave[/eluser]
Sorry for all of the questions lately. Once I am up to speed hopefully I can contribute to the forum in a meaningful way.
My question of the day is regarding moving my form validation callbacks to a library. I have read the documentation and searched the forum but can't find the specific answer I'm looking for. I can't figure out how to call the callback from my form controller. Now that I have moved the callback, it is not being run at all.
I started by creating MY_form_validation.php in application/libraries and placing the simple example username_check callback from the docs in it. This is all it contains:
Code:
class MY_form_validation extends CI_form_validation {
public function usernname_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message('username_check','The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
}
In my form controller, I have the rules set up in an array like so:
Code:
$config = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|required|min_length[4]|max_length[12]|callback_username_check|xss_clean'
), etc etc
When the callback was in the controller it worked fine, so I am guessing that I'm either not calling it correctly now, or it is not passing the error message back to the controller, or both.
Thanks in advance for any help!