I currently have a custom form and have successfully added a CAPTCHA to it, but I would like to set a cookie when the user passes the CAPTCHA successfully. I'm looking to add it into my form validate function on my .module file, but I can't figure out how to check if the user passed the CAPTCHA. Any ideas?

In case you want more information, my form is on a modal. When someone tries to up vote a post, it will initially take them to the modal where all they do is fill out a CAPTCHA to verify they're human and then they never get asked it again (I know, it's a little bit much, but it's one of the solutions we came up with and we're just trying to see how it would work out and if it's worth giving a shot). Let me know if you need any more information.

Comments

Stefan Lehmann’s picture

Not quite sure how you're using a captcha when you can't find out if it was filled out correctly? I guess that depends on the Captcha you're using.

I like cookies!

aplie’s picture

I'm using the math captcha through the basic captcha module. Is there anything else I should say? I can tell it is checking the captcha validation, because if I fill it out incorrectly it will be highlighted in red after I submit it. But the problem is I can't choose what happens when that part of the form specifically is validated (I want to set a cookie).

I found a resolution, but it required modifying captcha.module, which I think isn't preferable, so I'd still like to see if there's something better.

Stefan Lehmann’s picture

Couldn't you - assuming the form validated correctly - just add another submit handler via:

$form['#submit'][] = 'add_a_cookie_function';

.. and just set a cookie when the form has been submitted successfully and no other cookie has been set yet?

I like cookies!

aplie’s picture

Well... my boss told me to go in a new direction. So nevermind about this but thanks for the help!