Closed
Description
A form that does not map to the data of its parent should either be
- unmapped ("mapped" => false)
- virtual ("virtual" => true)
Unmapped forms are completely independent of their data. They have their own data, and children will be accessed to this data.
<?php
// Unmapped forms need to be filled with data explicitely
$form->add('address', 'form', array('mapped' => false));
$form->get('address')->setData($address);
// Maps to $address->getStreet()
$form->get('address')->add('street', 'text');
Virtual forms are not mapped to their parents data, but their children are.
<?php
// Virtual forms will not be mapped with data
$form->add('address', 'form', array('virtual' => true));
// Maps to $form->getData()->getStreet()
$form->get('address')->add('street', 'text');
Unmapped forms are useful if you want to embed forms that don't have a connection with the data of their parent form.
Virtual forms are useful if you use a form only in order to structure your view (see symfony/symfony#3995) or if you want to collect a set of field definitions that can be inserted ("copied") into the parent form (think traits).