2016-10-10 34 views
0

我想改變表單錯誤在FosUser密碼重置表單中呈現的方式。我想在密碼錶單中獲取錯誤消息,而不是默認情況下。覆蓋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

可能重複[覆蓋默認FOSUserBundle模板,無效果](http://stackoverflow.com/questions/24729115/overriding-default-fosuserbundle-template-no-effect) – Stannio

回答

-1

將{{form_errors(passwordField,{'attr':{'class':'form-error'}})}}部分移動到您希望錯誤顯示的位置,並且應該可以工作。現在錯誤會以表單的形式顯示,因爲這是它們被設置的位置。希望有所幫助!