简体   繁体   中英

Overriding FOSUserBundle registration form

I am using FOSUserBunlde. I have overrided its registration form using this tutorial: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md

So I have added a new firstname fied.

When using form_widget(form) in the twig file it works. however, I would like now to display each element of form seprately.

So I used :

<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">

     {{ form_errors(form) }}
    <div>     
        {{ form_label(form.firstname, "First name") }}
        {{ form_errors(form.firstname) }}
        {{ form_widget(form.firstname) }}
    </div>  
    <div>
       <input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
    </div>
</form>

The problem that the only field that is displayed is the form_label but the input box is not displayed. How can I fix that to display for example only the firstname field

I had a similar issue but I had commented out (incorrectly) the {{ form_widget(form) }}. Higher up in my code.

So I had done:

<!-- {{ form_widget(form) }} -->

When I should have done:

{# {{ form_widget(form) }} #} 

Or just removed it completely. I noticed you haven't shown any commented out code, so this probably isn't your issue, but thought I'd add this in case others saw your post and had something similar to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM