0
votes

Using this Link

Remove / Replace the username field with email using FOSUserBundle in Symfony2 / Symfony3

I tried to remove the Username from the registration form by Overriding the FOS User Bundle.

Form Type class is working fine.

But while rendering, it throws

Method "username" for object "Symfony\Component\Form\FormView" does not exist in FOSUserBundle:Registration:register_content.html.twig at line 3

I tried with this link to avoid this

Method "email" for object "Symfony\Component\Form\FormView" does not exist in SqliGestionCongeBundle:Default:add.html.twig.

I couldn't. Need expert assistance regarding this.

Update 1:

I also tried this link

http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html

Form Type class:

/* * Overridden FOSUserBundle RegistrationFormType. */

namespace Test\RegistrationBundle\Form;

use Symfony\Component\Form\AbstractType;

use Symfony\Component\Form\FormBuilderInterface;

class RegistrationFormType extends AbstractType

{

public function buildForm(FormBuilderInterface $builder, array $options)
{
     $builder->remove('username',array("mapped"=>false));
}

public function getParent()
{
    return 'fos_user_registration';
}

public function getName()
{
    return 'app_user_registration';
}

}

Twig File:

<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_widget(form) }}
<div>
    <input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>

1
@Matteo, Please assist me in this. It would be greatly helpfulNandakumar
can you please add your template code and form type codejahller
Hi @NandaKumar, it's really the best solution if you provide the code of the used twig-file and the FormType-file. Then it will be possible to help you.D3myon

1 Answers

0
votes

Thanks for @jahller and @D3myon comments. It helped me to diagnose the problem.

I had overridden the template form by including them as individual elements instead of form_widget(form).

I removed the username in the template file.

Problem Solved.