2011-12-20 10 views
5

tôi cần phải sử dụng Zend Captcha và viết mã follwoing:Làm cách nào để thêm hình ảnh xác thực vào biểu mẫu Zend?

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

     } 

    } 

?> 

Vấn đề tôi gặp phải là khi tôi hiển thị nó trong tôi tập tin "form.phtml" như:

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

Nó hiển thị như sau:

enter image description here

tức là Đang hiển thị 2 hộp văn bản.

Vui lòng giúp tôi chống lại tình huống này. :)

+0

Đăng đánh dấu nó tạo ra. – Dunhamzzz

+1

Bạn đang sử dụng Zend_Form đầy đủ, hoặc chỉ đặt hình ảnh xác thực? –

+0

Tôi đang sử dụng Zend_Form đầy đủ. – Ahsan

Trả lời

5

Bạn đang nhận được trường văn bản thứ hai bởi vì bạn đang sử dụng trình trang trí ViewHelper cho phần tử hình ảnh xác thực. Không đặt trình trang trí ViewHelper cho phần tử captcha và nó sẽ hoạt động.

0

hi tôi đang sử dụng mã này để loại bỏ trường bổ sung

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

đây là trang trí của tôi

'decorators' => $this->elementDecorators, 

này là mặc định trang trí

tôi chỉ cần loại bỏ ViewHelpre sử dụng mã followig

$captcha->removeDecorator('ViewHelper'); 

tôi hy vọng điều này sẽ làm việc cho bạn ... :)