Reputation: 11
I have a form, which is mapped to an object, and when I try to add not mapped field to this form, I can't retrieve the data.
This is my form :
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('comment', TextareaType::class, [
'label'=>'supidx.stateHistory.field.comment.short',
]
)
->add("file", FileType::class, [
'label'=>false,
'required'=>false,
'mapped'=>false
])
;
}
Controller :
if ($form->isSubmitted() && $form->isValid()) {
$file = $form->get("file");
dump($file);
Dump($file) returns null everytime.
I can't figure out why this doesn't work. Any help would be appreciated.
Upvotes: 1
Views: 3010
Reputation: 451
If file
is an object property, with an appropriate setter
$object->getFile();
Or if you want to retrieve any variable directly from your form
$form['file']->getData()
Upvotes: 2