Stevan Tosic
Stevan Tosic

Reputation: 7209

Remove default text from Symfony submit button

This is my button which should be just icon without text

{{ form_widget(form.submit, { 'attr': {'class': 'fa fa-search'} }) }}

I tried also to set value in FormType

->add('submit', 'submit', array(
                'label' => '',
                'attr' => array(
                    'value' => ''
                )
            ))

But nothing happen, or to say better, button contain

Submit

default text

Upvotes: 1

Views: 1677

Answers (3)

Stan Fad
Stan Fad

Reputation: 1234

You could try to use "space" for label attribute value. It's not "fair" way, as your button still has one "space", but i used to use it:

{{ form_widget(form.submit, {
                            'label' : ' ',
                            'attr': {
                                'class': 'fa fa-search'}
                            })
                        }}

Upvotes: 2

Wojciech Jasiński
Wojciech Jasiński

Reputation: 1490

Try this to set the label to false:

->add('submit', 'submit', array(
    'label' => false,
    'attr' => array(
        'value' => ''
    )
))

Upvotes: 1

Diego de los Reyes
Diego de los Reyes

Reputation: 41

You can replace:

{{ form_widget(form.submit, { 'attr': {'class': 'fa fa-search'} }) }}

by:

<button class="fa fa-search"></button>

And don't add the submit button by code.

Upvotes: -1

Related Questions