I have a simple user registration form with a checkbox for ‘accept terms’. I have set all fields to error_bubbling=false, but the error of the checkbox is rendered in the form_errors(form) section.
Here is my entity:
class User implements UserInterface, \Serializable, EquatableInterface
{
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
* @Assert\NotBlank(groups={"Registration"})
*/
private $isAcceptingTOS;
....
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'password_required' => true,
'validation_groups' => array('Registration', 'Default'),
));
}
}
My form type:
class RegistrationType extends AbstractType
{
$builder
->add('acceptingTOS', 'checkbox', array(
'error_bubbling' => false,
)),
....
}
And my template
<form action="{{ path('registration_create') }}" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}
{{ form_widget(form.acceptingTOS) }}
{{ form_label(form.acceptingTOS) }}
{{ form_errors(form.acceptingTOS) }}
{{ form_rest(form) }}
<input type="submit" />
</form>
Any hints?
I found the error.
I have to use isAcceptingTOS instead of acceptingTOS in the form type and in the template.