Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

}
like image 935
h0lend3r Avatar asked Jun 13 '17 18:06

h0lend3r


2 Answers

/**
 * @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

like image 132
Евгений Одинец Avatar answered Sep 20 '22 13:09

Евгений Одинец


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()
    ]);
}
like image 40
giurgiu rubin Avatar answered Sep 18 '22 13:09

giurgiu rubin