form issues in Symfony2

YANGEM

New Member
I have the following code in POST action in a form: \[code\] public function earlySignupAction(Request $request) { $user = new User(); $form = $this->createFormBuilder($user) ->add('username', 'text') ->add('email', 'text') ->add('password', 'password') ->getForm(); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $userRepository = $em->getRepository('MySiteUserBundle:User'); $userFoundByUsername = $userRepository->findOneBy(array('username' => $user->getUsername())); if ($userFoundByUsername) { $this->get('session')->getFlashBag()->add('notice', "Already registered!\n We will notify you soon!"); } $additionalInfoForm = $this->createForm(new UserType(), $user, array( 'mode' => 'additional_signup_info' )); return $this->render('MySiteMainBundle:Signup:index.html.twig', array( 'additionalInfoForm' => $additionalInfoForm->createView())); }else{ foreach($form->getErrors() as $key => $error){ $this->get('session')->getFlashBag()->add('error', $error->getMessage()); } } return $this->redirect($this->generateUrl('MySiteMainBundle_signup_fail')); }\[/code\]then inside the different controller (which is the controller of the page I am rendering MySiteMainBundle:Signup:index.html.twig after the first page), I have:\[code\]public function indexAction(Request $request) { $user = new User(); $additionalInfoForm = $this->createForm(new UserType(), $user, array( 'mode' => 'additional_signup_info' )); $additionalInfoForm->bind($request); if ($additionalInfoForm->isValid()) { $providerKey = $this->container->getParameter('fos_user.firewall_name'); $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles()); $this->container->get('security.context')->setToken($token); $em = $this->getDoctrine()->getEntityManager(); $em->persist($user); $em->flush(); return $this->redirect($this->generateUrl('MySiteMainBundle_marketplace')); }else{ return array( 'formValid' => false, 'additionalInfoForm' => $additionalInfoForm->createView() ); } return array('user' => $user, 'additionalInfoForm' => $additionalInfoForm->createView()); }\[/code\]The issue is that in the indexAction, when I try to print $User the value of username is null. Why is this?
 
Back
Top