6

i'm using Symfony 3.3.9 and when I'm trying to render a form I have the following error:

An exception has been thrown during the rendering of a template ("Unable to render the form because the block names array contains duplicates: "_fos_user_registration_form_errors", "user_errors", "user_errors", "fos_user_registration_errors", "form_errors".").

enter image description here

Thank you in advance for your help !

EDIT 17/09/2017 Here you go:

public function indexAction()
{
    /** @var $formFactory FactoryInterface */
    $formFactory = $this->get('fos_user.registration.form.factory');

    $form = $formFactory->createForm();

    return $this->render('AppTMMainBundle:Default:index.html.twig', array(
        'form' => $form->createView(),
    ));
}

My Twig:

{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register')}) }}
<div class="card-content">
    <h3 class="text-center title" style="color: #3C4858;margin:10px 0;">Inscription</h3>
    <div class="social text-center">
        <a class="btn btn-just-icon btn-round btn-facebook" href="{{ path('hwi_oauth_service_redirect',{'service': 'facebook'}) }}">
            <i class="fa fa-facebook"> </i>
        </a>
        <a class="btn btn-just-icon btn-round btn-twitter" href="{{ path('hwi_oauth_service_redirect',{'service': 'twitter'}) }}">
            <i class="fa fa-twitter"></i>
        </a>
        <a class="btn btn-just-icon btn-round btn-google" href="{{ path('hwi_oauth_service_redirect',{'service': 'google'}) }}">
            <i class="fa fa-google-plus"></i>
        </a>
    </div>
    <p class="description text-center">Ou de façon plus classique</p>
    <div class="row">
        <div class="col-xs-6">
            {{ form_label(form.firstname) }}
            {{ form_widget(form.firstname) }}
        </div>
        <div class="col-xs-6">
            {{ form_label(form.lastname) }}
            {{ form_widget(form.lastname) }}
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            {{ form_label(form.email) }}
            {{ form_widget(form.email) }}
        </div>
    </div>
    <div class="row">
        <div class="col-xs-6">
            {{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control', 'placeholder': 'form.password'}}) }}
        </div>
        <div class="col-xs-6">
            {{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control', 'placeholder': 'form.password_confirmation'}}) }}
        </div>
    </div>

    <!-- If you want to add a checkbox to this form, uncomment this code -->
    <div class="input-group">
        <div class="checkbox">
            <label>
                <input type="checkbox" name="optionsCheckboxes" checked="">
                {{ 'index.proceed.agree'|trans }}  <a href="{{ path('tm_main_policies_terms') }}">{{ 'index.proceed.cgu'|trans }}</a>.
            </label>
        </div>
    </div>
    <div class="footer text-center">
        <input type="submit" class="btn btn-primary btn-round" value="{{ 'index.action.subscribe'|trans }}">
    </div>
</div>
{{ form_end(form) }}
yceruto
  • 9,230
  • 5
  • 38
  • 65
Liogate
  • 145
  • 1
  • 7

2 Answers2

22

for anyone having such an exception:

You probably shouldn't extend a form type, but instead create your own and use getParent to inherit the behaviour. And if your class name is the same as an other type (excluding namespaces) you must override the getBlockPrefix from AbstractType.

The getBlockPrefix method from AbstractType uses the last part of fqcn (the class name) and you could have a duplicate block name.

0

I found the answer to my question.

That was from my RegistrationType class where I was trying to extends with another Type Class. getParent not working as well expected...

RegistrationType > UserType > FOS\UserBundle\Form\Type\RegistrationFormType

I move all fields from UserType in RegistrationType and it's working :)

Liogate
  • 145
  • 1
  • 7