createForm(::class, $user); $form->handleRequest($request); $errors = ''; if ($form->isSubmitted()) { if($form->isValid()) { // encode the plain password $user->set( $userPasswordHasher->hashPassword( $user, $form->get('password')->getData() ) ); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($user); $entityManager->flush(); $this->addFlash( 'success', 'Registered user successfully!' ); // do anything else you need here, like send an email return $this->redirectToRoute(''); } else { $errors = (string) $form->getErrors(true, true); } } return $this->render('registration/register.html.twig', [ 'registrationForm' => $form->createView(), 'errors' => $errors ]); } }