0

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>

Community
  • 1
  • 1
Nandakumar
  • 1,071
  • 2
  • 11
  • 30

1 Answers1

0

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.

Nandakumar
  • 1,071
  • 2
  • 11
  • 30
  • That sounds good. But keep in mind, that in special cases, you will have to remove a part of a form. Then you can call the `remove()` - function inside the controller directly after building the form. – D3myon Oct 15 '15 at 08:04