Symfony 4, how to make one of the fields are mandatory?

Good afternoon Forum,

how can I solve following issue?:

there are formular with multiple fields, all are mandatory.
but there are three fields of which must be at least one full.

Can anyone suggest how this can be done?

and can someone tell what is needed
resolver public function configureOptions(OptionsResolver $resolver)
and why the need for group validation?
June 5th 19 at 21:57
2 answers
June 5th 19 at 21:59
The easiest way is to manually check the fields and add error to the form:

$form = $this->createForm(MyFormType::class, $data);

$form->handleRequest($request);

if ($form->is submitted() && (/* Check fields */)) {
 $form->addError(new FormError('at least one of the fields must be filled'));
}

if ($form->is submitted() && $form->isValid()) {
 // Save results
}


For more complex cases (if you are going to reuse the form in other places) it is better to add your validator: https://coderwall.com/p/1blgvq/symfony2-custom-fie...
June 5th 19 at 22:01
See the implementation with @Assert\Callback

Find more questions by tags EAVSymfony