1

I have a field which is non-mapped and required.

$builder->add('termsAndConditions', CheckboxType::class, [
    'required' => true,
    'mapped' => false,
    'attr' => [
        'class' => 'c-custom-option',
    ],
]);

Clientside validation will throw an error when empty, but serverside says it's valid. Currently i do an extra check on form submission $form->isSubmitted() && $form->isValid() && $form->get('termsAndConditions')->getData()==true but the form->isValid() method shouldn't return true in my opinion

Quisse
  • 646
  • 1
  • 6
  • 24

1 Answers1

1

As you can see in docs:

If true, an HTML5 required attribute will be rendered. The corresponding label will also render with a required class.

This is superficial and independent from validation. At best, if you let Symfony guess your field type, then the value of this option will be guessed from your validation information.

So, as you can see, it's only about client side validation.

Manolo
  • 24,020
  • 20
  • 85
  • 130