Symfony2表单:如何在url中获取提交的值?

what I need is "onSubmit" to get the "query" value, and put it in the "_search_all" route, normally this would look like => {{ path('_search_all', {'slug': query_val} ) }} this way I can get a route like this in my browser localhost/search-all/symfony2

The current form

    <form class="searchbar" method="POST" action="{{ path('_search_all') }}">
        <input name="submit" type="submit" value="Search"/>
        <span>
         <input type="text" name="query" required/>
        </span>
    </form>

Solutions so far:

  1. method="GET" however this will create the "ugly" looking url
  2. use the friendsofsymfony/jsrouting-bundle

any inputs are welcome

You need to use onSubmit event and set a javascript variable which contains the path; as sample try something like:

var frm_action = "{{ path('_search_all', {'keyword' : ''}) }}";
$(document).ready(function() {
   $('#myForm').attr('action', frm_action + $('input[name="query"]').val());
});

and your need to add the ID to your form:

<form class="searchbar" method="POST" id="myForm" action="" >