Is there a way to set a validation callback that is not bound to a particular field, but is necessary to pass validation?
A:
Add a hidden field to your form and assign the callback to that a field. The callback doesn't have to relate to the contents of the hidden field.
Edit: Or, for that matter, you could assign the callback to any of your fields along other validation rules. No need for a hidden field.
kitsched
2010-09-08 13:01:02
+1
A:
Yes you can and here is a cruddy example:
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'lang:lang_username', 'required|callback_check_login');
Then for the callback:
public function check_login($username)
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$remember = $this->input->post('remember');
$login = $this->users_auth->login($username, $password, $remember);
if ($login !== TRUE)
{
$this->form_validation->set_message('check_login', $login);
return FALSE;
}
else
{
return TRUE;
}
}
Eric
2010-09-09 01:09:52
Good response Eric.
kitsched
2010-09-09 05:25:32