Symfony2 'The CSRF token is invalid. Please try to resubmit the form' 错误

当一个form页面http交互方法既有 GET 也有 POST时

提交form时必须遵循以下的流程

    if($request->getMethod() == 'POST'){  //先判断交互方法
        $form->submit($request);          //然后提交

        if($form->isValid())		  //有效性检测
        {
            $em = $this->getDoctrine()
                ->getEntityManager();
            $em->persist($blog);
            $em->flush();
            return $this->redirect($this->generateUrl('xxxxxx'));
        }
    }

    return $this->render('xxxxxxxx',array(
        'form' =>$form->createView()
    ));
}
 
  
如果忽略第一个if语句的话,就会出现The CSRF token is invalid. Please try to resubmit the form的错误

你可能感兴趣的:(Symfony)