1

I want to get Data in my form but it's return null for the select box who contains a forgein key of my entities and for my datetime, I have an error

Fatal Error: Call to a member function format() on null

I tried to getdata like this

$client = $form['id']['client']->getData();

this is a forgein key for my entity class and it in a select box, it's return null when I select option in select box, the name of select box is name = "appbundle_fournir[id][client]"

$date = $form['date']->getData()->format('d-m-Y');

for my datetime, I do something like that but it return an error I mention on top.

How can I do it properly to get my Data, thanks in advance and sorry for my bad english.

1 Answers1

1

To get data from a form in the newest Symfony versions you use the following code:

$data = $form->getData();

$date = $data->getDate();
$name = $data->getName();

Note that this requires mapped entities with getters and setters like getDate() and getName()

(the syntax for this has changed in the newer Symfony versions)