1

Symfony is generating a W3C error and I don't know how to resolve it : Element legend not allowed as child of element div in this context

here is the HTML line : <div class="form-group row"><legend class="col-form-label col-sm-2 col-form-label required">Date de naissance</legend><div class="col-sm-10"><div id="lessee_birthday" class="form-inline"><div class="sr-only"> I think it's generated by the formType

$builder
        ->add('civility', ChoiceType::class, [
            'label' => 'Civilite',
            'choices' => [
                'Mr' => 'Mr',
                'Mme' => 'Mme',
                'Mlle' => 'Mlle',
            ]
        ])
        ->add('name', TextType::class, ['label' => 'Prénom'])
        ->add('lastname', TextType::class, ['label' => 'Nom'])
        ->add('birthday', BirthdayType::class, ['label' => 'Date de naissance']) //here is the problem
        ->add('placeOfBirth', TextType::class, ['label' => 'Lieu de naissance'])
        ->add('email', EmailType::class, ['label' => 'Adresse email'])
        ->add('phoneNumber', TelType::class, ['label' => 'Numéro de telephone'])
    ;
Tom Paler
  • 67
  • 1
  • 11

1 Answers1

1

According to the specification <legend> tags belong directly underneath <fieldset> tags. You cannot mix them with <div> tags.

So you have to change in your templates how the BirthdayType field is rendered. Have a look at How to Customize Form Rendering in Symfony.

Paweł Napierała
  • 1,631
  • 10
  • 15
  • yeah I know, and I m checking this documentation again and again and again, but I don't find the solution, I tried different things, but not the good one – Tom Paler Mar 06 '19 at 15:12
  • How do you render the form? Can you post the template? Did you tried to override the field's template as described [here](https://symfony.com/doc/current/form/form_themes.html#creating-a-form-theme-in-the-same-template-as-the-form), e.g. like `{% block birthday_widget %} ...`? – Paweł Napierała Mar 06 '19 at 17:07