Can anyone see what I'm missing?
I'm using Codeigniter v1.72.
In the doc:
http://codeigniter.com/user_guide/libraries/form_validation.html
It states:
$this->form_validation->set_rules('username', 'Username', 'callback_username_check');
function username_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 class User extends Controller
I have in function register:
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'callback_username_check('.$username.')');
I have also tried
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'callback_username_check');
And
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'callback_username_check['.$username.']');
function username_check($str)
{
$this->load->model('User_model', '', TRUE);
$taken = $this->User_model->countUsername($str);
if($taken)
{
$this->form_validation->set_message('username_check', 'That username is already taken');
return FALSE;
}
else
return TRUE;
}
There are no errors at all, none of my approaches work, the code behaves like it's not there.
callback_username_check
setsusername_check
as a callback. – William Linton