Reputation: 1469
When i use the standard logic, it works, register without any problem.
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>
</form>
however when i manually override the fields, it looks like its registering, however, it doesn't register, error being thrown is CSRF token is invalid. Do i have to add anything else to make this code work?
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_widget(form.username) }}
{{ form_widget(form.email) }}
{{ form_widget(form.plainPassword.first) }}
{{ form_widget(form.plainPassword.second) }}
{{ form_widget(form.name) }}
{{ form_widget(form.Position) }}
{{ form_widget(form.Country) }}
{{ form_widget(form.notification) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>
</form>
Upvotes: 1
Views: 2379
Reputation: 1469
I found what the problem is, just needed to add
{{ form_rest(form) }}
This renders all fields that have not yet been rendered for the given form. It's a good idea to always have this somewhere inside your form as it'll render hidden fields for you and make any fields you forgot to render more obvious (since it'll render the field for you).
For more on form_rest()
see the symfony docs here
Upvotes: 5