Reputation: 174
I'm trying to make a form with possible subforms ( which can be added/removed on click of add/remove ), it works, but I can't get the unmapped variable from the form
MainForm
$builder
...
->add('courses', 'collection', array(
'type' => new CoursesType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
))
...
CoursesType form
$builder
...
->add('map', 'file', array(
'attr' => array(
'maxsize' =>'4M',
'accept' =>'image/*'
),
'required' => false,
'data_class' => null,
'mapped' => false,
));
...
The CoursesType form is mapped to an entity so I get the other form data, while I can't access the "map" field
Tried to dump the form, the data I get from "courses" , can't find "map" anywhere
EDIT 1: if I get rid of the mapping of courses to the entity "new CoursesType()" and add a mapping false, I get the data as I want(but in array), but this way I have to manually check all the data and add to a entity, can this be avoided ?
Upvotes: 1
Views: 480
Reputation: 1060
It is possible to string together $form->get()
statements before the ->getData()
$courses = $form->get('courses')
foreach ($courses as $course) {
$map = $course->get('map')->getData();
}
I don't know how this will work with adding and removing items from the collection but works ok for fixed collections
Upvotes: 1