0

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.

1 Answer 1

0

The first thing I would do is check that your conditional is running as expected.

if (!empty($input))
{
echo "I have Input"
exit();
}else{
echo "I have no Input"
exit();
}

Also, not all CodeIgniter functions are available in EE's branch, though this one seems to be there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.