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