nowiko
nowiko

Reputation: 2567

Get parameters from URL in Controller Symfony2

I try to submit my form by get method, but then in controller I cant get value, here is 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 problem related with this symbols %5D in the URL ? Can somebody help me?

Upvotes: 5

Views: 19483

Answers (2)

xurshid29
xurshid29

Reputation: 4210

Do like this, if you can't find QS values:

var_dump($request->query->all());

it shows all QS values;

In your case, you can access your QS data by:

$formData = $request->query->get('search_form');

or

$formData = $request->query->get($form->getName());

it returns array of values, after that you can access startPoints like this:

$formData['startPoints']

Upvotes: 11

Hayk Aramyan
Hayk Aramyan

Reputation: 323

You should write $request->get('startPoints') instead of $request->query->get('startPoint')

Upvotes: 0

Related Questions