向Zend Forms添加一些html [英] Add some html to Zend Forms

查看:61
本文介绍了向Zend Forms添加一些html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些简单的代码,可以让我将以下html添加到我的zend表单中:

Im looking for a simple bit of code that will let me add the following html into my zend form:

<div id="wmd-button-bar" class="wmd-panel"></div>

就这样,它需要在表单中我的"method"元素上方,但仅此而已.对于这样一个简单的动作,我找不到任何不涉及我学习火箭科学的方法(例如Zend Decorators).

Thats it, it needs to be above my 'method' element in the form but thats it. For such a simple action I cant find any methods that don't involve me learning rocket science (i.e Zend Decorators).

推荐答案

我目前唯一想到的方法是在表单中添加一个虚拟元素,并删除所有装饰器,但带有指定属性的"HtmlTag"除外在你的问题.删除装饰器意味着将不会呈现实际的元素-仅呈现HtmlTag装饰器.

The only way I can think of at the moment is to add a dummy element to the form and remove all decorators except an 'HtmlTag' with the attributes you specified in your question. Removing the decorators means that the actual element will not be rendered - only the HtmlTag decorator will be rendered.

所以假设您的表单是$ form:

so assuming your form is $form:

$form->addElement(
    'hidden',
    'dummy',
    array(
        'required' => false,
        'ignore' => true,
        'autoInsertNotEmptyValidator' => false,
        'decorators' => array(
            array(
                'HtmlTag', array(
                    'tag'  => 'div',
                    'id'   => 'wmd-button-bar',
                    'class' => 'wmd-panel'
                )
            )
        )
    )
);
$form->dummy->clearValidators();

请注意,您要防止对该元素进行任何验证.这只是一种方法-可能还有其他方法.

Note that you want to prevent any validation of the element. This is only one way - there are likely others.

输出:

<div id="wmd-button-bar" class="wmd-panel"></div>

有一个很好的

There is a good article describing decorators.

这篇关于向Zend Forms添加一些html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆