Argument 1 passed to Symfony\Component\Form\FormRenderer::renderBlock() must be an instance of ...\FormView, instance of ...\Form given
Asked Answered
F

2

28

Whole error is missiong namespace Symfony\Component\Form which is replaced with 3 dots, due to title maximum characters.

So, I am following the steps, that are presented in the docs and I'm unable to find source of the error I'm getting. If anyone could help, I'd greatly appreciate it.

Here is the method from my AuthController

/**
 * @Route("/register", name="registrationPage")
 */
public function showRegistrationPage(Request $request)
{
    return $this->render('auth/register.html.twig', [
        'register_form' => $this->createForm(RegisterType::class, (new UserInformation()))
    ]);
}

And here is the method, where I declare the form

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('firstname', TextType::class, ['attr' => ['class' => 'form-control']])
        ->add('secondname', TextType::class, ['attr' => ['class' => 'form-control']])
        ->add('email', EmailType::class, ['attr' => ['class' => 'form-control']])
        ->add('password', PasswordType::class, ['attr' => ['class' => 'form-control']])
        ->add('password_confirmation', PasswordType::class, [
            'label' => 'Confirm Password',
            'attr' => ['class' => 'form-control'],
            'mapped' =>false
        ])
        ->add('Register', SubmitType::class, ['attr' => ['class' => 'btn btn-primary']]);

}
Fahrenheit answered 13/6, 2017 at 18:16 Comment(1)
You're missing $form->createView(), check out symfony.com/doc/current/forms.html#handling-form-submissionsHagar
B
34
/**
 * @Route("/register", name="registrationPage")
 */
public function showRegistrationPage(Request $request)
{
    $form = $this->createForm(RegisterType::class, (new UserInformation()));

    return $this->render('auth/register.html.twig', [
        'register_form' => $form->createView()
    ]);
}

http://symfony.com/doc/current/forms.html#building-the-form

Bucolic answered 13/6, 2017 at 18:23 Comment(1)
An explanation is always helpful, without it in this answer I have to go back and forth with the question's code to find differences and work out what the fix was :(Embryo
D
5

the missing part was createView() method

/**
 * @Route("/register", name="registrationPage")
 */
public function showRegistrationPage(Request $request)
{
    return $this->render('auth/register.html.twig', [
        'register_form' => $this->createForm(RegisterType::class, (new UserInformation()))->createView()
    ]);
}
Dynamometry answered 26/3, 2019 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.