Using recaptcha with Zend_Form
0I was pleasantly surprised at how simple it was to integrate a good captcha solution with Zend_Form. Your form doesn’t have to extended a special object or anything; you just need to add a “captcha” element like so:
$this->addElement('captcha', 'captcha', array( 'label' => 'Please Type:', 'required' => true, 'captcha' => array( 'pubkey' => RECAPTCHA_PUBLIC_KEY, 'privkey' => RECAPTCHA_PRIVATE_KEY, 'captcha' => 'reCaptcha' ) ));
Be sure to change or set the defined variables for public and private keys provided to you with your recaptcha account. You don’t have to do anything to validate if the user entered the correct letters in your controller as Zend has already taken care of that part for you. As long as you’re using Zend’s isValid() method like so:
if ($form->isValid($request->getPost())) {
Hi I'm Nick Bartlett and thanks for visiting my blog. I'm not much of a writer; many of my posts are short and to the point while others are meant to be a reference for myself and other web developers.