The username Form Type

1.3.x 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
class MessageFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $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.