Add class for entering password in FOS Userbundle
I want to override the default FOS Userbundle registration form and add a custom class for password entry. So I copied register.html.twig and register_content.html.twig to the appropriate directory and edited register_content.html:
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_errors(form) }}
{{ form_row(form.email, {'attr': {'class': 'input-block-level'}}) }}
{{ form_row(form.username, {'attr': {'class': 'input-block-level'}}) }}
{{ form_row(form.plainPassword, {'attr': {'class': 'input-block-level'}}) }}
{#{{ form_row(form.submit, { 'label': 'Submit me' }) }}#}
{{ form_end(form) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans }}" />
</div>
{'attr': {'class': 'input-block-level'}}
-> it works for every input except plainPassword. I guess this is because it is repeated or something. Moreover, after deleting form_row with plainPassword and clearing cache, it still shows up, so it seems to come from a different file.
source to share
It doesn't come from another file when you call formend, it displays all your fields that you haven't mapped yet. to add a class to the plainPassword field, you must do this for each element, because a plain password is an array containing two fields (a password field and a password confirmation field). for this you need to do something like this:
{{ form_widget(form.plainPassword.first, { 'attr': {'class': 'myclass'} }) }}
{{ form_widget(form.plainPassword.second, { 'attr': {'class': 'myclass'} }) }}
source to share