0

I don't want some fields to show. I tried it like this

{{form_start(form)}}
{{form_widget(form)}}
{% do form.password.setRendered %}
{{ form_end(form) }}

But It doesn't work.

This is my form class. I don't want password field showing.

class UserType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
                ->add('username')
                ->add('email')
                ->add('password')
                ->add('type', ChoiceType::class, array(
                    'choices' => array(
                        'User' => 'ROLE_USER',
                        'Admin' => 'ROLE_ADMIN',
                        ),
                    ))
                ->add('save', SubmitType::class)
                ;
    }
}

2 Answers 2

4

You need to change the order of the lines and first tell that password field is rendered, before rendering the form itself:

{{ form_start(form) }}

{% do form.password.setRendered %}
{{ form_widget(form) }}

{{ form_end(form) }}
Sign up to request clarification or add additional context in comments.

Comments

-1

From the Form/UserType.php class, remove this line:

->add('password')

And it won't be rendered anymore.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.