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>

3
  • @Matteo, Please assist me in this. It would be greatly helpful Commented Oct 14, 2015 at 14:40
  • can you please add your template code and form type code Commented Oct 14, 2015 at 18:26
  • 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. Commented Oct 14, 2015 at 20:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.