我正在使用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']);
如何实现?
答案 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']);