我有一张用于注册的表格。在这种形式中,我有这个领域:
->add('plainPassword', RepeatedType::class, ['type' => PasswordType::class,
'first_options' => ['label' => 'Mot de passe'],
'second_options' => ['label' => 'Confirmation du mot de passe'],
'invalid_message' => 'Erreur de mot de passe',
'required' => true
])
当我尝试提交此表单时,两个密码字段都为空,它仍然提交表单并引发无效的约束错误:
An exception occurred while executing 'INSERT INTO user .... : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'password' cannot be null
输入渲染给出:
<input type="password" id="field_plainPassword_first" name="field[plainPassword][first]" required="required">
<input type="password" id="field_plainPassword_second" name="field[plainPassword][second]" required="required">
在控制器中:
$user = new Tutore();
$event = new GetResponseUserEvent($user, $request);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
$form = $this->createForm(RegistrationTutoreFormType::class, null);
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$username = $em->getRepository(Tutore::class)->getNewUsername(100000, 200000, 0);
$user->setUsername($username);
$user->setNom(ucfirst(strtolower($form->get('nom')->getData())));
$user->setPrenom(ucfirst(strtolower($form->get('prenom')->getData())));
$user->setEmail(strtolower($form->get('email')->getData()));
$event = new FormEvent($form, $request);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$this->userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
return $this->render('User/Registration/check_email.html.twig', ['user' => $user]);
}
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
$event = new FormEvent($form, $request);
$this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);
if (null !== $response = $event->getResponse()) {
return $response;
}
}
return $this->render('User/Registration/tutore.html.twig', ['form' => $form->createView()]);
知道为什么吗?