1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.captcha.operation">
4 <title>Captcha Operation</title>
7 All <acronym>CAPTCHA</acronym> adapter implement
8 <classname>Zend_Captcha_Adapter</classname>, which looks like the following:
11 <programlisting language="php"><![CDATA[
12 interface Zend_Captcha_Adapter extends Zend_Validate_Interface
14 public function generate();
16 public function render(Zend_View $view, $element = null);
18 public function setName($name);
20 public function getName();
22 public function getDecorator();
24 // Additionally, to satisfy Zend_Validate_Interface:
25 public function isValid($value);
27 public function getMessages();
29 public function getErrors();
34 The name setter and getter are used to specify and retrieve the
35 <acronym>CAPTCHA</acronym> identifier. <methodname>getDecorator()</methodname> can be used
36 to specify a <classname>Zend_Form</classname> decorator either by name or returning an
37 actual decorator object. The most interesting methods are
38 <methodname>generate()</methodname> and <methodname>render()</methodname>.
39 <methodname>generate()</methodname> is used to create the <acronym>CAPTCHA</acronym>
40 token. This process typically will store the token in the session so that you may compare
41 against it in subsequent requests. <methodname>render()</methodname> is used to render the
42 information that represents the <acronym>CAPTCHA</acronym>, be it an image, a figlet, a
43 logic problem, or some other <acronym>CAPTCHA</acronym>.
47 A typical use case might look like the following:
50 <programlisting language="php"><![CDATA[
51 // Creating a Zend_View instance
52 $view = new Zend_View();
54 // Originating request:
55 $captcha = new Zend_Captcha_Figlet(array(
61 $id = $captcha->generate();
62 echo "<form method=\"post\" action=\"\">";
63 echo $captcha->render($view);
66 // On subsequent request:
67 // Assume captcha setup as before, the value of $_POST['foo']
68 // would be key/value array: id => captcha ID, input => captcha value
69 if ($captcha->isValid($_POST['foo'], $_POST)) {