Search code examples
zend-framework2zend-formzend-form-element

Button content in ZF2 forms


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


Solution

  • You can simply use the disable_html_escape label's option. It works for me.

    $this->add(array(
            'type' => 'Button',
            'name' => 'submit',
            'options' => array(
                'label' => '<i class="icon icon-foo"></i> Submit',
                'label_options' => array(
                    'disable_html_escape' => true,
                )
            ),
            'attributes' => array(
                'type'  => 'submit',
                'class' => 'btn btn-success'
             )
        ));