Introduction to Zend Framework

 Learning Zend Framework

appendix

 Zend Framework Reference


  •  Zend_Gdata
  •  Zend_Http
  •  Zend_InfoCard
  •  Zend_Json
  •  Zend_Layout
  •  Zend_Ldap
  •  Zend_Loader
  •  Zend_Locale
  •  Zend_Log
  •  Zend_Mail
  •  Zend_Markup
  •  Zend_Measure
  •  Zend_Memory
  •  Zend_Mime
  •  Zend_Navigation
  •  Zend_Oauth
  •  Zend_OpenId
  •  Zend_Paginator
  •  Zend_Pdf
  •  Zend_ProgressBar
  •  Zend_Queue
  •  Zend_Reflection
  •  Zend_Registry
  •  Zend_Rest

  •  Zend_Search_Lucene
  •  Zend_Serializer
  •  Zend_Server
  •  Zend_Service
  •  Zend_Session
  •  Zend_Soap
  •  Zend_Tag
  •  Zend_Test
  •  Zend_Text
  •  Zend_TimeSync
  •  Zend_Tool
  •  Zend_Tool_Framework
  •  Zend_Tool_Project
  •  Zend_Translate
  •  Zend_Uri
  •  Zend_Validate
  •  Zend_Version
  •  Zend_View
  •  Zend_Wildfire
  •  Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Update 2011-11-16 - Revision 24438 - Version ZF 1.11.x

    18.2. Captcha Operation

    All CAPTCHA adapter implement Zend_Captcha_Adapter, which looks like the following:

    interface Zend_Captcha_Adapter extends Zend_Validate_Interface
    {
        public function 
    generate();

        public function 
    render(Zend_View $view$element null);

        public function 
    setName($name);

        public function 
    getName();

        public function 
    getDecorator();

        
    // Additionally, to satisfy Zend_Validate_Interface:
        
    public function isValid($value);

        public function 
    getMessages();

        public function 
    getErrors();
    }

    The name setter and getter are used to specify and retrieve the CAPTCHA identifier. getDecorator() can be used to specify a Zend_Form decorator either by name or returning an actual decorator object. The most interesting methods are generate() and render(). generate() is used to create the CAPTCHA token. This process typically will store the token in the session so that you may compare against it in subsequent requests. render() is used to render the information that represents the CAPTCHA, be it an image, a figlet, a logic problem, or some other CAPTCHA.

    A typical use case might look like the following:

    // Creating a Zend_View instance
    $view = new Zend_View();

    // Originating request:
    $captcha = new Zend_Captcha_Figlet(array(
        
    'name' => 'foo',
        
    'wordLen' => 6,
        
    'timeout' => 300,
    ));

    $id $captcha->generate();
    echo 
    "<form method=\"post\" action=\"\">";
    echo 
    $captcha->render($view);
    echo 
    "</form>";

    // On subsequent request:
    // Assume captcha setup as before, the value of $_POST['foo']
    // would be key/value array: id => captcha ID, input => captcha value
    if ($captcha->isValid($_POST['foo'], $_POST)) {
        
    // Validated!
    }
    digg delicious meneame google twitter technorati facebook

    Comments

    Loading...