How to edit the button content of a Button element (of a ZF2 form)? I can set a label, but i would like to insert some html code inside it.
$this->add(array(
'type' => 'Button',
'name' => 'submit',
'options' => array(
'label' => 'Modifica',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-warning'
)
));
Thanks
You can simply use the disable_html_escape label's option. It works for me.
The
FormButton
view helper will escape the button HTML content automatically as @Sam has correctly mentioned.The only way to avoid this would be to use a custom form button view helper. Rather than removing the escape functionality (as the button text content should be still be escaped); you could extend the view helper and add an additional option to allow you to render the html (I am assuming this is a bootstrap icon).
For example
Then create an 'invokable' configuration entry using the button view helper's default registered name ('form_button') in the service manager. This will then mean our view helper will be used instead of the default
Zend\Form\View\Helper\FormButton
.Lastly, change your button element specification to add a new 'icon' option
Some other points
If all you need is just an icon, using css is a much more simpler option, in form file you just add a custom css class to your button, and then in your style sheets add the icon to the class using before and content like this:
then in css: