Tuesday, December 17, 2013

ReCaptcha and PHP

Had to load ReCaptcha in a PHP page-- with ajax.  Two sources made this possible:

https://developers.google.com/recaptcha/docs/display
http://stackoverflow.com/questions/7261436/how-can-i-load-a-recaptcha-form-using-jquery-ajax-while-leaving-the-recaptcha-sc

I set it up such that I have recaptcha.php (which is the library) and my index.php.  Head on over to the recaptcha page to generate a key pair if you haven't already, by the way.

Include a script tag to load recaptcha_ajax.js
On document.ready, use recaptcha.create.  one of the arguments is a form on your page to add recaptcha to.

Your form can submit via ajax to another php page.  Just use the code block from the recaptcha library to check whether recaptcha succeeded.  If not, do something like:

header("HTTP/1.1 500 Internal Server Error");

No comments:

Labels

Blog Archive

Contributors