Access an unmapped field in Symfony2 Controller Access an unmapped field in Symfony2 Controller symfony symfony

Access an unmapped field in Symfony2 Controller


You can access unmapped field in form

$unmappedField = $form['unmapped_field']->getData();


taken from the symfony doc sf 2.5 (also tested with sf 2.3):

form type:

use Symfony\Component\Form\FormBuilderInterface;public function buildForm(FormBuilderInterface $builder, array $options){    $builder        ->add('task')        ->add('dueDate', null, array('mapped' => false))  ->add('save', 'submit');}

controller:

$form->get('dueDate')->getData();$form->get('dueDate')->setData(new \DateTime());

http://symfony.com/doc/current/book/forms.html#creating-form-classes (scroll down a little bit)