如何使用Zend表单描述添加自定义HTML标记

时间:2010-12-02 05:37:08

标签: php zend-framework zend-form

考虑我想要显示

复选框,复选框标签和之后的图像。

如何使用Zend Engine Form

创建相同的视图

我尝试如下

    $this->addElement(
            'Checkbox',
            "$key",
            array(
             'label'=>$value,
                'checkedValue' => "$key",
                'uncheckedValue' => '',
                'checked' => true,
             'disabled' => false,
          )
        );

     $element = $this->getElement($key);         


       $element->setDecorators(
   array(
     'ViewHelper',
     array('Label', array('tag' => 'dt', 'class'=>'hidden')),
     array('Description',array('escape'=>false,'tag'=>' span')), //escape false because I want html output
    )
   );

     $element->setDescription('<img name="help_'.$key.'" id="help_'.$key.'" src="/application/modules/User/externals/images/what-is-this.gif"/>');

$element->setDescription('<img name="help_'.$key.'" id="help_'.$key.'" src="/application/modules/User/externals/images/what-is-this.gif"/>');

但是显示复选框,描述图像和复选框标签为上标。

请帮助

2 个答案:

答案 0 :(得分:19)

$element->getDecorator('Description')->setEscape(false);

这样可以防止转义说明内容。

答案 1 :(得分:2)

查看AnyMarkup Decorator

您可以将该装饰器添加到元素装饰器列表中,指定具有APPEND位置的图像的标记。

相关问题