我有一个要求用户注册的两步表单。这是一些代码:
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
,但我实际上不是。知道为什么吗?