Two buttons in a row (Bootstrap form theme for Symfony2)

6.4k views Asked by At

I'm using the Bootstrap form theme for Symfony2 (bootstrap_3_horizontal_layout.html.twig):

I've added two buttons on a form:

$builder
    // some code here ... 
    ->add('save', 'submit', ['label' => 'save'])
    ->add('cancel', 'submit', ['label' => 'cancel']);

And they are rendered this way: enter image description here

I need that they be situated on the same row: enter image description here

How can it be achieved?

3

There are 3 answers

2
Yoshi On BEST ANSWER

Following the

Symfony Best Practises: Add buttons in the templates, not in the form classes or the controllers.

E.g.:

{{ form_start(form) }}
  {{ form_widget(form) }}

  <div class="row">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" value="save" class="btn btn-primary">save</button>
      <button type="submit" value="cancel" class="btn btn-default">cancel</button>
    </div>
  </div>
{{ form_end(form) }}
4
Max Nijholt On

Have you tried to put the 2nd line on the same line as the first?

Like so:

->add('save', 'submit', ['label' => 'save']) ->add('cancel', 'submit', ['label' => 'cancel']);
4
Matteo On

Just add a style float left to the save button. This works for me:

    ->add('save', 'submit', ['label' => 'save', 'attr' => array('style' => 'float: left')])
    ->add('cancel', 'submit', ['label' => 'cancel']);