The username Form Type

2.0 version
Maintained

The username Form Type

FOSUserBundle provides a convenient username form type, named fos_user_username. It appears as a text input, accepts usernames and convert them to a User instance:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class MessageFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('recipient', 'FOS\UserBundle\Form\Type\UsernameFormType');

        // if you are using Symfony < 2.8 you should use the old name instead
        // $builder->add('recipient', 'fos_user_username');
    }
}

Note

If you don't use this form type in your app, you can disable it to remove the service from the container:

1
2
3
# app/config/config.yml
fos_user:
    use_username_form_type: false

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.