Symfony Type error: Too few arguments to function FormRenderer::renderBlock()

12,155

The error comes from cached files, so in a first step, you should delete all files/dirs in /var/cache/.

Do it manually (not by console)

The form ending should be:

{{ form_end(form) }}
Share:
12,155

Related videos on Youtube

andreaem
Author by

andreaem

I'm a FullStack PHP Developer from Italy, skilled in PHP,HTML, CSS, JS, jQuery. Develop with new technologies such as Angular, React and Vue.

Updated on June 09, 2022

Comments

  • andreaem
    andreaem 7 months

    I got a Form that must to handle the helpdesk requests in Symfony 3.3, i will render this using twig.

    Controller

    /**
     * @Route("/helpdesk/apri_ticket", name="helpdesk_apri")
     */
    public function helpdeskNewAction(Request $request) {
        $entity = new HelpDesk();
        $form = $this->createFormBuilder($entity)
            ->add('title',TextType::class,array(
                'label' => 'Titolo',
                'attr' => array('class' => 'form-control')
            ))
            ->add('type',ChoiceType::class, array(
                'choices' => array(
                    'Scegli...' => '0',
                    'Assistenza' => '1',
                    'Problema' => '2',
                    'Errore' => '3'
                )
            ))
            ->add('message', TextType::class, array(
                'label' => 'Messaggio',
                'attr' => array('class' => 'form-control')
            ))
            ->add('submit',SubmitType::class, array(
                'label' => 'Apri Ticket',
                'attr' => array('class' => 'btn-success')
            ))
            ->getForm();
        $form->handleRequest($request);
        if($form->isSubmitted() && $form->isValid()) {
            print 'ok';
        }
        return $this->render('help/help.create.html.twig', array(
            'form' => $form->createView())
        );
    }
    

    Here is the easy twig template:

    {{ form_start(form) }}
        {{ form_widget(form.title) }}
        {{ form_widget(form.type) }}
        {{ form_widget(form.message) }}
    {{ form_end() }}
    

    Here is the Error:

    Type error: Too few arguments to function Symfony\Component\Form\FormRenderer::renderBlock(), 0 passed in /vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 83 and at least 2 expected
    

    What's wrong with this? FormRenderer::renderBlock ask for at least 2 arguments, FormView and BlockName and optional an array containing variables. This is the first time I got this error and I don't know what is this BlockName.

  • andreaem
    andreaem over 5 years
    I've take this way but nothing changed, see the updated error shown that just change the file causing it. In addition i've disabled the cache for the twig environment
  • Michał G over 5 years
    and what happen if you try to render form by {{ form(form) }} in twig?
  • Michał G over 5 years
    and check form_end
  • andreaem
    andreaem over 5 years
    Damn, that was the error! Surely Symfony can explain better these errors.
  • Dariux
    Dariux about 5 years
    What if you do not have variable form? If you did not build form object, but used just plain html?

Related