Symfony Form not showing correct error (pending on constellation)

I have an issue with the constrains-check of my form and the correct display of errors.

describtion of problem

The form has three checkboxes and two of them are mandatory to be checked by the user (accepting Terms and Conditions stuff).

  • if only one of the mandatory checkboxes (either the first or the secound) is not checked, the error is displayed correctly
  • if both mandatory checkboxes are not checked, no error is displayed at all

analysis already done

  • looping through errors link show that there is really no error
  • if i add an additional form-field (textbox), the above problem disappears (but I don’t want an addional field).

BookingTermsAndConditionsFormType.php

class BookingTermsAndConditionsFormType  extends AbstractType {
    public function buildForm(FormBuilderInterface $builder, array $options) {

        $builder
            ->add('checkbox1', CheckboxType::class, [
                'label'      => 'accept <a href="#" target="_blank">Terms and Conditions</a>.*',
                'label_html' => true,
                'label_attr' => ['class' => 'switch-custom'],
                'constraints' => [
                    new IsTrue([
                        'message' => 'Accepting Terms and Conditions are mandatory.',
                    ]),
                ],
            ])
            ->add('checkbox2', CheckboxType::class, [
                'label'      => 'accept <a href="#" target="_blank">privacy policy</a>*',
                'label_html' => true,
                'label_attr' => ['class' => 'switch-custom'],
                'constraints' => [
                    new IsTrue([
                        'message' => 'Accepting privacy policy is mandatory.',
                    ]),
                ],
            ])
            ->add('checkbox3', CheckboxType::class, [
                'label'      => 'I want the newsletter.',
                'label_html' => true,
                'label_attr' => ['class' => 'switch-custom'],
            ]);
    }

    public function configureOptions(OptionsResolver $resolver) {
        $resolver->setDefaults([]);
    }
}

_formTermsAndConditions.html.twig

{{ form_start(bookingTermsAndConditionsForm, {
    attr: {
        class: 'form-general',
        novalidate: 'novalidate',
        id: 'form_booking_terms_and_conditions'
    }
}) }}


<div class="row">
    <div class="col-10 offset-2">
        <div>
            {{ form_row(bookingTermsAndConditionsForm.checkbox1) }}
            {{ form_row(bookingTermsAndConditionsForm.checkbox2) }}
            {{ form_row(bookingTermsAndConditionsForm.checkbox3) }}
        </div>
    </div>
</div>



{{ form_end(bookingTermsAndConditionsForm) }}

Question

What is wrong here?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *