Update – check out the post at AmpTools, if you’re using a copy of Zend Framework version 1.7.8 or above – the below code may not work for you.
—–
Recently on a project I was developing using the Zend Framework, I needed to validate a form using a CAPTCHA image.

CAPTCHA example image
For those who don’t know, CAPTCHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart. Ever been to a website and seen an image like the one to the right? Basically, it’s a way to make sure a human is filling out the form and not just some robot. How? Robots can’t decifer what words *might* be from an image – only a human can.
Zend Framework has a set of great classes included to take away a lot of the headaches involved with setting up a CAPTCHA system. The one I use is Zend_Captcha_Image, which creates an image for you and sets up a Session so you will be able to validate all information appropriately. Problem is, there’s little documentation out there on this.
The best example I found was on Robert Basic’s Blog. My only gripe about it was that it used Zend_Form.
Zend_Form is a great class and all, but if you’re like me, you don’t like using it because you give up the control you get over Form creation + validation. It’s a great way to skip writing HTML for a form – but what if your client wants a very specific design attached to their form? Then Zend_Form becomes a hassle to design to a specification. And yes, Zend_Form makes validation easy, but what if your client wants to set up very specific validation messages? Again, Zend_Form becomes more trouble than it’s worth. Yes, it is flexible enough as a class to edit it any way you want, but I feel NOT using Zend_Form will ultimately make your forms more flexible.
So, beyond the break, I’ll show you everything you need to know to use Zend_Captcha_Image WITHOUT Zend_Form! If you’d like to learn the implementation using Zend_Form, please visit Robert Basic’s Blog.
(more…)
no responses