Reputation: 55
This is my input type
->add(‘year’, ChoiceType::CLASS, array(‘choices’ => $array, ‘attr’ => array(‘onchange’ => ‘this.form.submit()’)));
Onchange page is reloading and data is submitted. Then in controller I can access value like this:
$_POST[‘year’].
The thing is I would like to get $_POST in symfony’s way:
$form[‘year’]->getData();
I don’t know why only $_POST[‘year’] works and no result with $form[‘year’]->getData().
Upvotes: 1
Views: 1938
Reputation: 2654
You can use for POST request :
$request->request->get('year');
For GET request:
$request->query->get('year');
For FILE queries:
$request->files.
Upvotes: 3
Reputation: 7902
You can get a single item from the form data like;
$year = $form->get('year')->getData();
In this example 'year' is the name given to the field you are asking for (as per your form builder)
Upvotes: 2