如何将字符实体放入ZF2中的formSubmit的值中 [英] How to put a character entity in the value of a formSubmit in ZF2
问题描述
当我像这样在ZF2表单中创建一个提交按钮时:
When I create a submit button in a ZF2 form like this:
$this->add(array(
'name' => 'save_closebutton',
'attributes' => array(
'type' => 'submit',
'value' => 'Save & Move On »',
'id' => 'save_closebutton',
'class' => 'btn btn-default'
),
));
,然后在这样的视图中放置一个formSubmit
元素:
and then put a formSubmit
element in the view like this:
echo $this->formSubmit($form->get('save_closebutton'));
ZF2将按钮中的文本呈现为Save & Move On »
,而不呈现代码表示的字符.
ZF2 renders the text in the button as Save & Move On »
without rendering the character that the code represents.
我非常确定问题出在formSubmit
助手中,因为检查该元素表明该助手创建了该子控件:
I'm pretty sure that the problem is in the formSubmit
helper, because inspecting the element shows that the helper creates this:
<input id="save_closebutton" class="btn btn-default" type="submit" value="Save & Move On »" name="save_closebutton">
但是如果我只是在视图中回显相同的字符串,
but if I simply echo the same string in the view,
echo '<input id="save_closebutton" class="btn btn-default" type="submit" value="Save & Move On »" name="save_closebutton">';
按钮显示正确.
如何获取formSubmit
传递字符而不是代码?
How do I get formSubmit
to pass the character and not the code?
推荐答案
FormSubmit
帮助器在输出之前转义属性名称和值,AFAIK无法在不提供自定义帮助器的情况下禁用它.
The FormSubmit
helper escapes attribute names and values before output, AFAIK there's no way to disable that without providing custom helpers.
由于您的Submit元素只是一个按钮,因此可以使用Button
元素和FormButton
视图助手来解决您的问题.元素具有标签选项,可让您禁用标签上的html转义,并且助手会尊重该设置.
Since your submit element is just a button, you can use the Button
element and the FormButton
view helper to solve your problem. The element has a label option which allows you to disable html escaping on the label, and the helper respects that setting.
在表单中创建您的提交按钮...
Create your submit button in the form ...
$this->add(array(
'name' => 'save_closebutton',
'type' => 'Button', // \Zend\Form\Element\Button
'options' => array(
'label' => 'Save & Move On »',
// inform the FormButton helper that it shouldn't escape the label
'label_options' => array(
'disable_html_escape' => true,
),
),
'attributes' => array(
'type' => 'submit', // <button type="submit" .../>
'id' => 'save_closebutton',
'class' => 'btn btn-default'
),
));
使用FormButton
助手来渲染元素...
Use the FormButton
helper to render the element ...
echo $this->formButton($form->get('save_closebutton'));
这篇关于如何将字符实体放入ZF2中的formSubmit的值中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!