Problems with FOSUserBundle with plainPassword in twig form

I define my own twig layout for registering a new user, and everything turned out the way I want, except for the plainPassword field from FOSUserBundle.

<p class="left"> {{ form_widget(form.plainPassword) }} </p> <div class="clearfix"></div> 

The above code displays both the password and the verification unit. I would like to break this down into 4 elements form.plainPassword.label, form.plainPassword.field, form.plainPassword2.label and form.plainPassword2.field. I cannot figure out what to put in the form_label() and form_widget() calls.

 <p class="left"> {{ form_label( ??? ) }} {{ form_widget( ??? ) }} </p> <p class="left"> {{ form_label( ??? ) }} {{ form_widget( ??? ) }} </p> <div class="clearfix"></div> 

I guess this can be done.

+4
source share
2 answers

I had the same problem. My solution (looks like an official :):

 {{ form_label (form.plainPassword.first) }} {{ form_widget (form.plainPassword.first) }} {{ form_label (form.plainPassword.second) }} {{ form_widget (form.plainPassword.second) }} 

Hope this helps!

+24
source

This blog post shows how to display a duplicate field in a branch.

http://blogsh.de/2011/10/19/how-to-use-the-repeated-field-type-in-symfony/

But in a nutshell this worked for me:

 {{ form_label (form.plainPassword.children['New Password']) }} {{ form_widget (form.plainPassword.children['New Password']) }} {{ form_label (form.plainPassword.children['Confirm Password']) }} {{ form_widget (form.plainPassword.children['Confirm Password']) }} 

I have to say that I'm sure using .children is not the best / official way to do this, but it works!

+2
source

Source: https://habr.com/ru/post/1402236/


All Articles