我正在使用FOS用户捆绑包+ Symfony2.3.我想覆盖FOS用户包表单.覆盖并希望在头文件中添加登录和注册表单.对于show in header我使用的是javascript.例如,当我点击tab-2然后打开注册表单
有一件事我只是覆盖这个,这是有效的,但当注册表格调用其他HTML时,它不起作用
我这样做但这是我的错误:
The CSRF token is invalid. Please try to resubmit the form.
我不知道为什么 ?
我的档案是:
HeaderController.php
createForm(new RegistrationFormType()); return array('registration_form' => $registrationForm->createView()); } } ?>
报头(index.html.twig): -
{# Signup #}
RegistrationFormType.php
add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle')) ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle')) ->add('plainPassword', 'repeated', array( 'type' => 'password', 'options' => array('translation_domain' => 'FOSUserBundle'), 'first_options' => array('label' => 'form.password'), 'second_options' => array('label' => 'form.password_confirmation'), 'invalid_message' => 'fos_user.password.mismatch', )) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => "XYZ\UserBundle\Entity\User" )); } public function getName() { return 'xyz_user_registration'; } }
的services.xml
%fos_user.model.user.class%
RegisterController.php
container->get('fos_user.registration.form'); $formHandler = $this->container->get('fos_user.registration.form.handler'); $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled'); $process = $formHandler->process($confirmationEnabled); if ($process) { $user = $form->getData(); $authUser = false; if ($confirmationEnabled) { $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail()); $route = 'fos_user_registration_check_email'; } else { $authUser = true; $route = 'fos_user_registration_confirmed'; } $this->setFlash('fos_user_success', 'registration.flash.user_created'); $url = $this->container->get('router')->generate($route); $response = new RedirectResponse($url); if ($authUser) { $this->authenticateUser($user, $response); } return $response; } return $this->container->get('templating')->renderResponse('XYZUserBundle:Registration:register.html.'.$this->getEngine(), array( 'form' => $form->createView(), )); } } ?>
config.yml
fos_user: db_driver: orm firewall_name: main user_class: XYZ\UserBundle\Entity\User registration: form: type: xyz_user_registration name: xyz_user_registration_form validation_groups: [Registration, Default]
谢谢!
表单提交使用隐藏输入中包含的CRSF令牌.您不要在视图中插入此输入.尝试在提交按钮之前插入此行:
{{ form_rest(registration_form) }}