Zend framework2 如何将字符实体放入ZF2中formSubmit的值中
在ZF2表单中创建提交按钮时,如下所示:Zend framework2 如何将字符实体放入ZF2中formSubmit的值中,zend-framework2,form-submit,view-helpers,Zend Framework2,Form Submit,View Helpers,在ZF2表单中创建提交按钮时,如下所示: $this->add(array( 'name' => 'save_closebutton', 'attributes' => array( 'type' => 'submit', 'value' => 'Save & Move On »',
$this->add(array(
'name' => 'save_closebutton',
'attributes' => array(
'type' => 'submit',
'value' => 'Save & Move On »',
'id' => 'save_closebutton',
'class' => 'btn btn-default'
),
));
echo $this->formSubmit($form->get('save_closebutton'));
然后在视图中放置formSubmit
元素,如下所示:
$this->add(array(
'name' => 'save_closebutton',
'attributes' => array(
'type' => 'submit',
'value' => 'Save & Move On »',
'id' => 'save_closebutton',
'class' => 'btn btn-default'
),
));
echo $this->formSubmit($form->get('save_closebutton'));
ZF2将按钮中的文本呈现为Save&Move On»代码>而不渲染代码所表示的字符
我很确定问题出在formSubmit
helper中,因为检查元素表明helper创建了以下内容:
<input id="save_closebutton" class="btn btn-default" type="submit" value="Save & Move On »" name="save_closebutton">
但如果我只是在视图中回显相同的字符串
echo '<input id="save_closebutton" class="btn btn-default" type="submit" value="Save & Move On »" name="save_closebutton">';
echo';
按钮已正确渲染
如何让formSubmit
传递字符而不是代码?帮助程序在输出前转义属性名称和值,如果不提供自定义帮助程序,则无法禁用
由于提交元素只是一个按钮,因此可以使用按钮
元素和表单按钮
查看帮助器来解决问题。元素有一个标签选项,允许您在标签上禁用html转义,并且帮助器尊重该设置
在表单中创建提交按钮
$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'
),
));
为什么不直接写'value'=>'Save&Move On»,
?可能会使用'value'=>'Save&Move On»
,但我的问题的目的是确定如何也包括html代码,如'Save&Move On'