Search code examples
authenticationsymfonycsrffosuserbundle

Symfony2 FosUser : CSRF token issue


I use the authentification system provided by FOSUser bundle

Everything was doing fine but recently when clicking on :

     <form action="{{ path('fos_user_registration_register') }}" method="post">                          
                           <button class="btn btn-small btn-success" type="submit">S'inscrire</button>                     
     </form>  

that generated the error: The CSRF token is invalid. Please try to resubmit the form.

none of the view nor controller of FOSUserBundle have being modified...!?

How come this happened and how can this be fixed?


Solution

  • Make sure your twig templates have

    {{form_rest(form)}} 
    

    or your php files have

    <?php echo $view['form']->rest($form) ?> 
    

    if you specify the individual fields