Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Zend表单中添加验证码?_Php_Zend Framework_Zend Form_Captcha - Fatal编程技术网

Php 如何在Zend表单中添加验证码?

Php 如何在Zend表单中添加验证码?,php,zend-framework,zend-form,captcha,Php,Zend Framework,Zend Form,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

我需要使用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 ?>

它显示以下内容:

i、 e.显示2个文本框


请帮助我应对这种情况。:)

您将获得第二个文本字段,因为您正在对captcha元素使用ViewHelper装饰器。不要为captcha元素设置ViewHelper装饰器,它应该可以工作。

您好,我正在使用此代码删除额外字段

$captcha = new Zend_Form_Element_Captcha('captcha',array('label' => 'Write the chars to the field',  
                                                            'captcha' => array(
                                                                'captcha' => 'Image',   
                                                                'wordLen' => 3,
                                                                'timeout' => 300,
                                                                'font' => APPLICATION_PATH.'/../public/font/two.ttf', 
                                                                'imgDir' => APPLICATION_PATH.'/../public/captcha/', 
                                                                'imgUrl' => 'http://localhost/projx/public/captcha/'

                                                            ),
                                            'decorators' => $this->elementDecorators,
                                            ));   
                                            $captcha->removeDecorator('ViewHelper');
这是我的装饰师

 'decorators' => $this->elementDecorators,
这是默认的装饰器

 'decorators' => $this->elementDecorators,
我只是使用下面的代码删除ViewHelpre

$captcha->removeDecorator('ViewHelper');

我希望这对你有用……:)

你是在使用完整的Zend_表单,还是只是把验证码放出来?如果你只是回显$this->表单,你会得到什么?