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

h0lend3r picture h0lend3r · Jun 13, 2017 · Viewed 14.3k times · Source

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']]);

}

Answer

Евгений Одинец picture Евгений Одинец · Jun 13, 2017
/**
 * @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