walidacja warunkowa w formie

    public function onSubmit(FormEvent $event): void
    {
        $form = $event->getForm();

        $requiredFormData[] = $form['code'];
        $requiredFormData[] = $form['address']['street'];
        $requiredFormData[] = $form['address']['houseNumber'];
        $requiredFormData[] = $form['address']['lat'];
        $requiredFormData[] = $form['address']['lng'];

        foreach ($requiredFormData as $single) {
            if (empty($single->getData())) {
                $single->addError(
                    new FormError($this->translator->trans('xxxx', [], 'XXXBundle'))
                );
            }
        }
    }
Dodawanie komentarzy wyłączone

Komentarze 1