php – 如何在Zend表单中添加Captcha?

我需要使用Zend Captcha并编写以下代码:

<?php

    require_once ('Zend/Form.php');

    class Form_Signup extends Zend_Form {

        public function __construct( $options = null ) {

            parent::__construct( $options );

            // Set method
            $this->setMethod('post');

            // Elements array
            $elements = array();

            $element = new Zend_Form_Element_Captcha('captcha', array('label'   => "",
                                                                      'captcha' => array('captcha' => 'Image',
                                                                                         'name'    => 'myCaptcha',  
                                                                                         'wordLen' => 5,  
                                                                                         'timeout' => 300,  
                                                                                         'font'    => 'font/monofont.ttf',  
                                                                                         'imgDir'  => 'captcha/',  
                                                                                         'imgUrl'  => '/captcha/')
                                                                     )
                                                    );
            $elements[] = $element;

            // Submit Button
            $element = $this->CreateElement('submit', 'Signup');
            $element->setLabel('Signup');
            $elements[] = $element;

            // --------------------------
            // Add elements to the form
            // --------------------------

            // update tabindex
            foreach ($elements as $index => $element) {
                $element->setAttrib('tabindex', ($index + 1));
            }

            $this->addElements($elements);
            $this->setElementDecorators(array('ViewHelper'));

            // Set form decorator (what script will render the form)
            $this->setDecorators(array(array('ViewScript' , array('viewScript' => 'signup/form.phtml'))));

        }

    }

?>

我遇到的问题是,当我在我的“form.phtml”文件中显示它时,如:

<?= $this->element->captcha ?>

它显示以下内容:

即它显示2个文本框.

请帮助我抵制这种情况.

上一篇:VMware虚拟机下NAT模式配置


下一篇:Windows 和 Ubuntu 的网络能互相 ping 通之后,linux无法上网原因:①路由没设置好,②DNS 没设置好