0

Before with my Symfony project with the version 6.1, I could do it.

{{ form_start(form, {'attr': {'id': 'form-add-meeting'}}) }}
    {{ form_widget(form) }}
    
    <label for="">Date *</label>
    <input class="form-control" type="text" id="datepicker" name="datepicker" />

    <label class="time-selector mt-3" for="">Horaire *</label>
    <input type="time" name="time" class="form-control time-selector" id="time-selector-input" />

{{ form_end(form) }}

Now when I try with the version 7.3 of Symfony, I get that error : "An exception has been thrown during the rendering of a template ("Warning: Array to string conversion") in form_div_layout.html.twig at line 374"

I searched everywhere on the web and I don't find any answer, any solution.

I tried to add field by field with form_row and it doesn't work. Form_label doesn't work too.

The only way I succeed to make it work is with form_widget for each field but it's less interesting for me because after I have to add the errors messages, the label inside the view manually.

Here is the FormType:

public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('jump', JumpAutocompleteField::class)
            ->add('purchase_custom_link', TextType::class, [
                'mapped' => false,
                'required' => false,
                'label' => 'N° Sport Découverte',
                'attr' => [
                    'class' => 'form-control mb-3'
                ]
            ])
            ->add('purchase_item', OrderLinkAutocompleteField::class)
            ->add('client_lastname', TextType::class, [
                'required' => false,
                'label' => 'Nom',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 60
                ]
            ])
            ->add('client_name', TextType::class, [
                'required' => false,
                'label' => 'Prénom',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 60
                ]
            ])
            ->add('client_email', EmailType::class, [
                'required' => false,
                'label' => 'Adresse email',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 120
                ]
            ])
            ->add('client_phone', TextType::class, [
                'required' => false,
                'label' => 'Numéro de téléphone',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 10
                ]
            ])
            ->add('client_age', TextType::class, [
                'required' => false,
                'label' => 'Âge',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 2
                ],
            ])
            ->add('client_height', TextType::class, [
                'required' => false,
                'label' => 'Taille (cm)',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 3
                ]
            ])
            ->add('client_weight', TextType::class, [
                'required' => false,
                'label' => 'Poids (kg)',
                'attr' => [
                    'class' => 'form-control mb-3',
                    'maxlength' => 3
                ]
            ])
        ;
    }
    
8
  • This question is missing context (which line is 374), but I would try replacing the form_widget(form) by form_rest(form). See form_rest(form_view, variables) @ Symfony documentation's How to Customize Form Rendering. TwigStan @ GitHub might be helpful in debugging your issue. Commented Aug 18 at 13:11
  • Thank you for your answer. That line is in the source code of Symfony: vendor/symfony/twig-bridge/Resources/views/Form/form_div_layout.html.twig:374 In my code, put up the line 130 that is the render: return $this->render('admin/meeting/index.html.twig'... Commented Aug 18 at 14:00
  • form_rest gives the same result Commented Aug 18 at 14:02
  • Line 374 just renders the label. It looks like something's off in the form definition (some BC issue between 6.x and 7.x). Please add the form declaration php code to your questions so we can see what's going on there. Commented Aug 18 at 14:31
  • 1
    Thank you everybody for your help. I tried to troubleshoot removing one field at a time but the result is the same. The only way it works is using form_widget so I had an HTML tag by hand up. I enjoy less the benefits of the FormType of Symfony but I lost enough time. I have to go further. I think, I will delete the question. I don't find a good answer anywhere included Chatgpt. So I have to move on. Thanks to everybody. Commented Aug 20 at 13:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.