I've created an EE custom addon that processes a simple enquiry form. All works well but I'm trying to add a callback function to my validation rules and it appears to be completely ignored.
Here's my call to the validation rule:
ee()->form_validation->set_rules('url', 'URL', 'callback_honeypot'); // Honeypot field
and my callback function (which is in the same file) is:
public function honeypot($input)
{
if (!empty($input))
{
ee()->form_validation->set_message('honeypot', '<p>Not all is as it should be...</p>');
return FALSE;
} else {
return TRUE;
}
}
Will the standard CI form validation callback method not work with EE?
Update / workaround:
Although I haven't got the callback method to work, a simple workaround for (in my case) a honeypot field is to hide the field on the frontend form and use something like this:
ee()->form_validation->set_rules('nickname', 'Nickname', 'max_length[1]');
So if the 'nickname' field has more than one character entered into it, the validation fails.
Alternatively, you could do this:
$honeypot_field = ee()->input->post('nickname', TRUE);
and only process the form if the following conditions are met:
if (ee()->form_validation->run() == TRUE && (empty($honeypot_field)))
But it doesn't answer the question of why the proper CI callback functionality doesn't work in EE.