createForm(RegistrationFormType::class, $user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var string $plainPassword */ $plainPassword = $form->get('plainPassword')->getData(); // encode the plain password $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); $entityManager->persist($user); $entityManager->flush(); // do anything else you need here, like send an email return $this->redirectToRoute('home'); } return $this->render('registration/register.html.twig', [ 'registrationForm' => $form, ]); } }