2

我在我的Zend_Form中有一個圖像元素。如何手動在Zend_Form中設置dd元素的ID?

$dropDownButton = new Zend_Form_Element_Image('image_button'); 
$dropDownButton->setOptions(array('image'=>'/images/image1.png', 
           'style'=>'padding-top:20px', 
           ) 
           ); 
$this->addElement($dropDownButton); 

以上圖像作爲某種形式的「提交」按鈕。 HTML輸出是:

<dd> 
<input type="image" style="padding-top: 20px;" alt="" src="/images/image1.png" id="image_button" name="image_button"> 
</dd> 

對於其他所有的Zend表單元素,我得到的是這樣的:

<dd id="name-element"></dd> 

我如何可以做同樣在圖像的Zend表單元素的情況下?

有沒有一種方法可以設置ID?

回答

3

我這樣做,它的工作:

$dropDownButton->setDecorators(array 
           (array('ViewHelper'), 
           array('Errors'), 
           array('HtmlTag', 
             array('tag' => 'dd','id'=>'add_drop_down-element')))); 

輸出是:

<dd id="add_drop_down-element"></dd> 
1

我認爲$element->setAttrib('id', 'my_id');將工作。

+0

我試過了,並沒有設置

元素的ID。 但它確實改變了內部標籤的ID,雖然那不是我想要的。 – 2010-01-27 23:55:30

+0

啊對不起,我誤解了你的問題。對於你想要的,你的解決方案是正確的:) – robertbasic 2010-01-28 07:51:15