Search code examples
phpformssymfony-2.8

symfony 2.8 FOSUserBundle legacyFormHelper: get input field of form in twig template


I am trying to restyle the register form of the FOSUserBundle, i try to putt the input in my template line by line like this.

{{ form_widget(form.username) }}
{{ form_widget(form.first_name) }}

This works, but when i try to do this with the password en confirmation password it doesn't work.

Here is the line of the form 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'),
        'first_options' => array('label' => 'form.password'),
        'second_options' => array('label' => 'form.password_confirmation'),
        'invalid_message' => 'fos_user.password.mismatch',

I try to put it in the temlate like this:

{{ form_widget(form.plainPassword) }}
{{ form_widget(form.password_confirmation) }}

but it is not working, i tried some other things also but i cant figure it out.

Thanks in advance.


Solution

  • I found the answer to my question:

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

    Full information about the register template customization can be found here:

    https://www.amalhichri.net/user-management-with-fosuserbundle/