Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove a form field in embedded forms from symfony 2 controller

Tags:

I have a form as below:

class AdminEmployerForm extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
            ->add('firstName', 'text')
            ->add('user', new AdminUserForm());
    }
}


class AdminUserForm extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
            ->add('username', 'text')
            ->add('email', 'text');
    }
}

I am calling AdminEmployerForm in controller and I want to remove email field of AdminUserForm from AdminEmployerForm:

$form = $this->createForm(new AdminEmployerForm, $employer);
//i want to do something like $form->remove('email')

how can i do use $form->remove() to remove field in embedded form? Is it possible to remove a field of embedded form from controller?