Add some html to Zend Forms(向 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>
就是这样,它需要在表单中我的方法"元素之上,仅此而已.对于如此简单的操作,我找不到任何不涉及我学习火箭科学(即 Zend 装饰器)的方法.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:向 Zend Forms 添加一些 html


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01