如何手动设置Zend_Form中的dd元素的id?

时间:2010-01-27 19:40:18

标签: zend-framework zend-form zend-form-element zend-form-sub-form

我的Zend_Form中有一个图像元素。

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

2 个答案:

答案 0 :(得分: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 :(得分:1)

我认为$element->setAttrib('id', 'my_id');可行。