如何修复 FOSUserBundle 提交?
How to fix FOSUserBundle submitting?
我试图覆盖模板,但无法提交表单。当我单击提交按钮时,数据将保存到 URL。当我删除我的模板并使用默认模板时,一切正常。我没有覆盖 RegistrationController。
Symfony v4.3.4
我的 register_content.html.twig
{% trans_default_domain 'FOSUserBundle' %}
<section class="sign-in">
<div class="container">
<div class="row">
<div class="col-12 col-sm-10 col-md-8 col-lg-6 offset-sm-1 offset-md-2 offset-lg-3 top-negative">
<h1 class="text-center">{{ 'registration.title'|trans }}</h1>
<form class="sign-in-form mt-74">
<div class="row">
{{ form_start(form, {'method': 'POST', 'action': path('fos_user_registration_register')}) }}
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.email, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.email_reg'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.plainPassword.first, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.password'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.plainPassword.second, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.repeat_password'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.firstname, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.first_name'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.lastname, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.last_name'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.tel, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.tel'|trans }}) }}
</div>
<div class="col-12 text-center">
{{ form_widget(form.submit, {'attr': {'class': 'button button-dark'}}) }}
</div>
{{ form_end(form) }}
</div>
</form>
</div>
</div>
</div>
</section>
我的 layout.html.twig
{% extends 'base.html.twig' %}
{% block main %}
{% block fos_user_content %}
{% endblock fos_user_content %}
{% endblock %}
您有 2 个表单打开标签。 <form class="sign-in-form mt-74">
和使用 {{ form_start(form, {'method': 'POST', 'action': path('fos_user_registration_register')}) }}
创建的那个(同样是两个表单标签结束)。
您可以在 form_start 标签中添加您的 class="sign-in-form mt-74"
... {'method': 'post', 'action': 路径('....'), 'attr': {'class': 'sign-in-form mt-74' }} ...
我试图覆盖模板,但无法提交表单。当我单击提交按钮时,数据将保存到 URL。当我删除我的模板并使用默认模板时,一切正常。我没有覆盖 RegistrationController。
Symfony v4.3.4
我的 register_content.html.twig{% trans_default_domain 'FOSUserBundle' %}
<section class="sign-in">
<div class="container">
<div class="row">
<div class="col-12 col-sm-10 col-md-8 col-lg-6 offset-sm-1 offset-md-2 offset-lg-3 top-negative">
<h1 class="text-center">{{ 'registration.title'|trans }}</h1>
<form class="sign-in-form mt-74">
<div class="row">
{{ form_start(form, {'method': 'POST', 'action': path('fos_user_registration_register')}) }}
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.email, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.email_reg'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.plainPassword.first, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.password'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.plainPassword.second, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.repeat_password'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.firstname, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.first_name'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.lastname, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.last_name'|trans}}) }}
</div>
<div class="col-12 col-sm-6 mb-20">
{{ form_widget(form.tel, {'label': false,'attr': {'class': 'form-input', 'placeholder': 'registration.tel'|trans }}) }}
</div>
<div class="col-12 text-center">
{{ form_widget(form.submit, {'attr': {'class': 'button button-dark'}}) }}
</div>
{{ form_end(form) }}
</div>
</form>
</div>
</div>
</div>
</section>
我的 layout.html.twig
{% extends 'base.html.twig' %}
{% block main %}
{% block fos_user_content %}
{% endblock fos_user_content %}
{% endblock %}
您有 2 个表单打开标签。 <form class="sign-in-form mt-74">
和使用 {{ form_start(form, {'method': 'POST', 'action': path('fos_user_registration_register')}) }}
创建的那个(同样是两个表单标签结束)。
您可以在 form_start 标签中添加您的 class="sign-in-form mt-74"
... {'method': 'post', 'action': 路径('....'), 'attr': {'class': 'sign-in-form mt-74' }} ...