我正在尝试更改FosUser密码重置表单中呈现表单错误的方式。我希望在密码表单下获取错误消息,而不是默认情况下的上面。
此FormType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('plainPassword', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\RepeatedType'), array(
'type' => LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\PasswordType'),
'options' => array('translation_domain' => 'FOSUserBundle'),
'attr' => [
'class' => 'form-group has-feedback'
],
'first_options' => array('label' => false,
'attr' => [
'placeholder' => 'New Password'
]
),
'second_options' => array('label' => false,
'attr' => [
'placeholder' => 'Repeat Password'
]),
'invalid_message' => 'fos_user.password.mismatch',
));
}
模板
<body class="reset-page">
<div class="reset-box">
<div class="logo">
<a href="">
<img src="">
</a>
</div>
<div class="reset-box-body">
{{ form_start(form, { 'action': path('fos_user_resetting_reset', {'token': token})}) }}
{% for passwordField in form.plainPassword %}
<div class="form-group has-feedback">
{{ form_widget(passwordField, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors(passwordField, { 'attr': {'class': 'form-error'} }) }}
</div>
{% endfor %}
<input type="submit" class="btn btn-primary btn-block" value="Submit" />
{{ form_end(form) }}
</div>
</div>
但是在结果中,所有错误都呈现在形式之上。
答案 0 :(得分:-1)
将{{form_errors(passwordField,{&#39; attr&#39;:{&#39; class&#39;:&#39; form-error&#39;}})}}部分移至您的任何地方希望显示错误,这应该工作。现在,错误将显示在表单中,就像它们被设置的位置一样。希望有所帮助!