26

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

}
h0lend3r
  • 431
  • 1
  • 5
  • 11
  • 5
    You're missing `$form->createView()`, check out https://symfony.com/doc/current/forms.html#handling-form-submissions – JimL Jun 13 '17 at 18:18

2 Answers2

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

quaertym
  • 3,917
  • 2
  • 29
  • 41
  • 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 :( – James Nov 17 '22 at 13:18
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()
    ]);
}
giurgiu rubin
  • 71
  • 1
  • 3