Question

I just learn how to use fosuserbundle, I just added "name" column to entity and database field, and now, the registration form is shows like this :

Email       :[_______________________________]
Username    :[_______________________________]
Password    :[_______________________________]
Verification:[_______________________________]
Name        :[_______________________________]<-name

my question is how to make it orders like this since I added 'name, field later.

Email       :[_______________________________]
Name        :[_______________________________]<-order name here
Username    :[_______________________________]
Password    :[_______________________________]
Verification:[_______________________________]

should I make it ordered from database table or just from Form factory ?

thanks,

Was it helpful?

Solution

Copy vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/views/Registration/register_content.html.twig into app/Resources/FOSUserBundle/views/Registration/register_content.html.twig and make changes like:

vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/views/Registration/register_content.html.twig

<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>

app/Resources/FOSUserBundle/views/Registration/register_content.html.twig

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

    {{ form_widget(form.email) }}
    {{ form_widget(form.name) }}
    {{ form_widget(form.username) }}
    {{ form_widget(form.plainPassword.first) }}
    {{ form_widget(form.plainPassword.second) }}

    {{ form_end(form) }}
    <input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</form>

OTHER TIPS

One way to do it as @repincln's answer. But other way around is to update the form builder, as you have already extended to add your field. I think it would be much easier/cleaner if you just re-arrange your form while building it. Assuming you have override the form as per FOSUserBundle Documentation

public function buildForm(FormBuilderInterface $builder, array $options){

   $builder
       ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
       ->add('name')
       ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
       ->add('plainPassword', 'repeated', array(
             'type' => 'password',
             'options' => array('translation_domain' => 'FOSUserBundle'),
             'first_options' => array('label' => 'form.password'),
             'second_options' => array('label' => 'form.password_confirmation'),
             'invalid_message' => 'fos_user.password.mismatch',
          ))
       ;
}

Use which one you like.

Happy Coding...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top