How to pass query parameter in form submit? I have a form :

function buildForm(array $form, FormStateInterface $form_state) {
    $form['edit'] = array(
          '#type' =&gt; 'textfield',
    );
    $form['submit'] = array(
          '#type' =&gt; 'submit',
          '#value' =&gt; t('Go'),
          //'#markup' =&gt; "&lt;div&gt;&lt;a href='?word=1'&gt;Go&lt;/a&gt;&lt;/div&gt;",
        );
    return $form;
}


Now I want is; when I submit form,$form_state-&gt;getValue('edit'); should get appended as a query parameter in form route.

Let's say my form route is:

mymodule.admin_page:
  path: '/mypage'
  defaults:
    _form: '\Drupal\mymodule\Form\myform'


And when I hit submit button of form, the route should get changed to /mypage?word=$form_state-&gt;getValue('edit').

I tried below approach, but it is throwing error:

Created 1 more route with a parameter:

mymodule.word:
  path: '/mypage/{word}'
  defaults:
    _controller: '\Drupal\mymodule\Controller\AdminController::myfunction'


And in my form submit function,

function submitForm(array &amp;$form, FormStateInterface $form_state) {

    $data = $form_state-&gt;getValue('edit');
    $url = Url::fromRoute('mymodule.word',['word'=&gt;$data]);
    $form_state-&gt;setRedirectUrl($url);
   }


But when I hit submit button, it is giving me error,


  Uncaught PHP Exception
  Symfony\Component\Routing\Exception\MissingMandatoryParametersException:
  "Some mandatory parameters are missing"
Stick with your original route definition:

mymodule.word:
  path: '/mypage'
  defaults:
    _controller: '\Drupal\mymodule\Controller\AdminController::myfunction'


Then set your submit handler to this:

function submitForm(array &amp;$form, FormStateInterface $form_state) {

  $data = $form_state-&gt;getValue('edit');
  $url = Url::fromRoute('mymodule.word', [], ['query' =&gt; ['word' =&gt; $data]]);
  $form_state-&gt;setRedirectUrl($url);
}