连续两个按钮(Symfony2的Bootstrap表单主题)

时间:2015-08-06 08:32:17

标签: twitter-bootstrap symfony twig symfony2-forms

我正在使用the Bootstrap form theme for Symfony2(bootstrap_3_ 水平 _layout.html.twig):

我在表单上添加了两个按钮:

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

它们以这种方式呈现: enter image description here

我需要他们位于同一排: enter image description here

如何实现?

3 个答案:

答案 0 :(得分:13)

关注

  

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) }}

答案 1 :(得分:2)

只需在左侧添加一个样式浮动按钮即可。这对我有用:

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

答案 2 :(得分:-5)

您是否尝试将第二行与第一行放在同一行?

像这样:

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