I would like to expand @Wouter J's answer because it did not work for me, as above.
I needed to define the data_class class in formbuilder:
class SignupHouseRentFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('signup', SignupFormType::class, array( 'data_class' => Signup::class )) ->add('house_rent', HouseRentFormType::class, array( 'data_class' => HouseRent::class )); } }
then in the controller I had to use the same namespace for data binding:
class SignupHouseRentController extends Controller { public function indexAction(Request $request) { $signup = new Signup(); $houseRent = new HouseRent(); $mergedData = array( 'signup' => $signup, 'houseRent' => $houseRent ); $form = $this->createForm(SignupHouseRentFormType::class, $mergedData); $form->handleRequest($request); } }
source share