Get parameters from url in symfony2 controller
I am trying to submit my form with the get method, but then in the controller I cannot get the value, here is the controller:
var_dump($request->query->get('startPoint')); // its NULL
My form:
<form id="s_f" action ="{{ path('trip_search') }}" method="get" novalidate="">
{{ form_widget(search_form, {'attr': {'class': 'search_form'} }) }}
</form>
Generated URL:
http://example.com/app_dev.php/search_trips?search_form%5BstartPoint%5D=3123123&search_form%5BendPoint%5D=&search_form%5
Maybe the problem is with these characters %5D
in the URL? Can anyone help me?
+3
source to share
2 answers
Do this if you cannot find the QS values:
var_dump($request->query->all());
displays all QS values;
In your case, you can access your QS data:
$formData = $request->query->get('search_form');
or
$formData = $request->query->get($form->getName());
it returns an array of values, after that you can access startPoints
like this:
$formData['startPoints']
+8
source to share