Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Form with subform

I have a user form and a contact form in my user form i tried to add my contact form to the user form

When I tried to add

$builder->add(
            'contact',
            new ContactType()
        );

It failed with

You cannot add children to a simple form.
Maybe you should set the option "compound" to true?

tried to set the compound but didnt work

/**
 * {@inheritdoc}
 */
public function configureOptions(OptionsResolver $resolver)
{
    $defaults = array(
        'compound' => true,
        'inherit_data' => true,
    );

    $resolver->setDefaults($defaults);
}
like image 577
Alexander Schranz Avatar asked Jun 26 '15 10:06

Alexander Schranz


1 Answers

The compound option is by default set to true.

  1. How did you extend your form type class? AbstractFormType, or something else?
  2. Did you override getParent() method?

This could explain compound being set to false.

like image 152
Jovan Perovic Avatar answered Sep 22 '22 10:09

Jovan Perovic