2012-07-24 40 views
2

我使用Zend_Form創建的驗證碼是這樣的:Zend的驗證碼HTML

class Form_Signup extends Zend_Form { 

    public function __construct(array $options = null) { 

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

     // other elements here   

     // captcha 
     $captcha = new Zend_Form_Element_Captcha('captcha', array(
       'id'=>'captcha', 
       'title'=>'Security Check.', 
       'captcha' => array(
       'captcha' => 'Image', 
       'required' => true, 
       'font'=> 'fonts/ARIALN.TTF', 
       'wordlen'=>'4', 
       'width'=>'200', 
       'height'=>'50', 
       'ImgAlign'=>'left', 
       'DotNoiseLevel'=>'30', 
       'LineNoiseLevel'=>'7', 
       'Expiration'=>'1000', 
       'fontsize'=>'30', 
       'gcFreq'=>'10', 
       'imgdir'=> 'images/captcha/', 
       'ImgAlt'=>'Captcha', 
       'imgurl'=>'/images/captcha/' 
       ))); 
     $captcha->removeDecorator('HtmlTag') 
     ->removeDecorator('Label') 
     ->addDecorator('Label');   

     // add captcha 
     $this->addElement($captcha);   
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'signup/signup-form.phtml'))));  
    } 

} 

它生成HTML這樣的:

<img width="200" height="50" alt="Captcha" src="/images/captcha/cabf4d4d759ae8e4b7404b95e032e231.png"> 
<input type="hidden" name="captcha[id]" value="cabf4d4d759ae8e4b7404b95e032e231" title="Security Check." id="captcha"> 
<input type="text" name="captcha[input]" id="captcha" value="" title="Security Check."> 

但我想這樣下面的圖片驗證碼的文本框:

<img width="200" height="50" alt="Captcha" src="/images/captcha/cabf4d4d759ae8e4b7404b95e032e231.png"> 
<br /> 
<input type="hidden" name="captcha[id]" value="cabf4d4d759ae8e4b7404b95e032e231" title="Security Check." id="captcha"> 
<input type="text" name="captcha[input]" id="captcha" value="" title="Security Check."> 

任何想法?

謝謝

+0

[Customize zend_form Captcha output?](http://stackoverflow.com/questions/5131743/customize-zend-form-captcha-output) – markus 2012-07-24 18:15:55

回答

1

Zend驗證碼元素裝飾器很少被複合。麪糊解決方案是創建我們自己的裝飾器。一旦你完成了它。您可以更改順序,只要你想

你可以找到完整的答案here

如果你不着急,如果你有足夠的時間,然後通過this article通過Methew解釋如何使用裝飾玩去了。

差不多相同的問題我問here,我不想創建一個單獨的裝飾類,但沒有得到任何正確的答案。然後我做了一些CSS技巧,並迫使<input type='text'>下降。所以唯一的解決方案是生成自定義驗證碼裝飾類。

如果你沒有收到任何東西,請告訴我。謝謝