0
我有一个2步表单,要求用户注册。下面是一些代码:symfony2表单没有正确呈现密码
public function earlySignupAction(Request $request)
{
$user = new User();
$form = $this->createFormBuilder($user)
->add('username', 'text')
->add('email', 'email')
->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'));
}
现在我想要什么/什么应该发生的是,第二个表格($additionaInfoForm
)密码字段将被从已上$form
输入的密码预填,但我实际上它WASN “T。任何想法为什么?
我试过,但它没有工作,以及 – adit
的always_empty选项不工作对我也。 – Rooster242
对我而言,任何人都知道为什么? – soipo