我正在尝试使用 Symfony 和Braincrafted Bootstrap模块创建基于 Twitter Bootstrap 的水平表单。我已经从文档中复制了示例但是我的表单没有正确呈现
我的代码如下
class MyController extends Controller {
/**
* @Route("/")
* @Method("GET")
* @Template
*/
public function someAction() {
$form = $this->createForm(new HorizontalFormType());
return array("horizontalForm" => $form->createView());
}
}
此类取自文档:
class HorizontalFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('email', 'text', array(
'label' => 'Email',
'attr' => array('placeholder' => 'Email')
));
$builder->add('password', 'password', array(
'label' => 'Password',
'attr' => array('placeholder' => 'Password')
));
$builder->add('checkbox', 'checkbox', array('label' => 'Remember me'));
}
public function getName() {
return 'horizontal_form';
}
}
模板代码也被复制
<form class="form-horizontal">
<legend>Legend</legend>
{{ form_widget(horizontalForm, {'form_type': 'horizontal'}) }}
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
生成的表单 HTML 是
<form class="form-horizontal ng-pristine ng-valid">
<legend>Legend</legend>
<div id="horizontal_form">
<div>
<label class="required" for="horizontal_form_email">Email</label>
<input type="text" placeholder="Email" required="required" name="horizontal_form[email]" id="horizontal_form_email">
</div>
<div>
<label class="required" for="horizontal_form_password">Password</label>
<input type="password" placeholder="Password" required="required" name="horizontal_form[password]" id="horizontal_form_password">
</div>
<div>
<label class="required" for="horizontal_form_checkbox">Remember me</label><input type="checkbox" value="1" required="required" name="horizontal_form[checkbox]" id="horizontal_form_checkbox">
</div>
<input type="hidden" value="fea7c498a01aebd814baf4a9f57df4b6e3646195" name="horizontal_form[_token]" id="horizontal_form__token">
</div>
<div class="control-group">
<div class="controls">
<button class="btn" type="submit">Sign in</button>
</div>
</div>
</form>
注意我也在我的项目中使用 AngularJS(因此 ng 指令被添加到表单的类列表中)。
我错过了什么?