Micchaleq
Micchaleq

Reputation: 433

Symfony 2, form and jQuery on change submit

I want to create form with auto submit, so I used jquery. I think that i have problem with translate url.

My form :

<form action="edit" method="get" >
    <select name="id" onchange="this.form.submit();">
        {% for panel in panele %}
        <option value="{{ panel.setting.id }}">{{ panel.nazwa }}</option>
        {% endfor %}
    </select>
</form>  

And when I want to change option, I get this in url "edit?id={id}", and when i try use it in controller (route).

@Route("/edit?id={id}")

I got error:

No route found for "GET /settings/edit"

(/settings is global route for controller)

Upvotes: 0

Views: 2298

Answers (1)

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

The action attribute of your form has no URL. Your should generate the url using twig path expression.

<form action="{{ path('edit_route') }}" method="get" >

Replace the route identifier edit_route with the name of your route. Also, clear browser and symfony caches.

Upvotes: 1

Related Questions