Zend_Form_Element_Captcha using ReCaptcha

Example of usage of ReCaptcha webservice using Zend Framework. I did have a basic login form and I wanted to add human verification. Although other versions exists I liked this one for the social benefit it brings. ReCaptcha digitize old books using the user input as a verification tool, which I think is a very cool idea.

Here is my Zend_Form_Element_Captcha :

// first I set a ReCaptcha service with the keys that you get by registering in ReCaptcha website
$public = $config->recaptcha->public;
$private = $config->recaptcha->private;
$recaptcha_service = new Zend_Service_ReCaptcha($public, $private);

// then set the Recaptcha adapter
$adapter = new Zend_Captcha_ReCaptcha();
$adapter->setService( $recaptcha_service );

// then set the captcha element to use the ReCaptcha Adapter
$recaptcha = new Zend_Form_Element_Captcha('recaptcha', array(
'label' => "Are you a human?",
'captcha' => $adapter
//Then only add the element to the form:
$form->addElement ( $recaptcha );

That’s it.

About this entry