2011-12-20 5 views
5

私はZendのキャプチャを使用する必要があるとfollwoingコードを書いた:CaptchaをZend Formに追加するには?

<?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 ?> 

それを表示次

enter image description here

それは2つのテキストボックスが表示されている。すなわち。

この状況に対処するのを助けてください。 :)

+0

それが生成するマークアップを投稿してください。 – Dunhamzzz

+1

あなたは完全なZend_Formを使用しているのですか、または単にcaptchaを外していますか? –

+0

私は完全なZend_Formを使用しています。 – Ahsan

答えて

5

captcha要素にViewHelperデコレータを使用しているため、2番目のテキストフィールドが表示されます。 captcha要素にViewHelperデコレータを設定しないでください。これはうまくいくはずです。

0

こんにちは私はちょうどfollowigコード

を使用してViewHelpreを削除これは私のデコレータ

'decorators' => $this->elementDecorators, 

で、これはデフォルトのデコレータ

あるに

$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'); 

余分なフィールドを削除するには、このコードを使用しています

$captcha->removeDecorator('ViewHelper'); 

私はこれがあなたのために働くことを願っています。:)

関連する問題