Question

I use FOSUserBundle with a custom registration form that extends the one provided by the bundle. I want to override the validation so it doesn't check for a username (I generate it). I have read that this can be achieved thru the usage of validation groups.

These are the relevant parts of my form:

public function buildForm(FormBuilderInterface $builder, array $options)
{

    parent::buildForm($builder, $options);

    ...

    $builder->remove('username');

    ...

}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'Ysu\Bundle\SiteBundle\Entity\User',
        'validation_groups' => array('my-registration-group'),
        'cascade_validation' => true
    ));
}

...

However the username is still validated with the validation files provided by the bundle. I found out that $options (array) contains an array validation_groupswhich in its turn contains the 'Registration' group, so that is why the field is still validated. However, I don't know how to remove it. If I unset it from $optionsbefore passing it to parent::buildFormit will still contain the Registration group.

Does anyone know how to solve this?

Was it helpful?

Solution

Turns out you can configure the validation groups for the FOSUserBundle's forms in config.yml:

fos_user:
    ....
    registration:
        form:
            validation_groups:  [default, registration_mod]
            ....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top