問題描述
我正在尋找一段簡單的代碼,可以讓我將以下 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!