Controller is loading twice after search form is submitted I created a custom module that I consume an external api. I have also created a custom form (its action points to controller url) which filters the data. However, when I press the search button and the controller is loading, despite I get the right results immediately the controller is reloading and consequently I loose the filtered results.
How I can stop this behaviour?
This is my code so far:
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
   
    $ada = $form_state-&gt;getValue('ada');
    $sector = $form_state-&gt;getValue('sector');
    $sub_sector = $form_state-&gt;getValue('sub_sector');

if ($sub_sector=='') {
  $subject_unit=$sector;
} else {
  $subject_unit=$sub_sector;
}

    $datefrom = $form_state-&gt;getValue('datefrom');
    $dateto = $form_state-&gt;getValue('dateto');

    $params=[
    'type'=&gt;$subject_unit,
    'datefrom'=&gt;$datefrom,
    'dateto'=&gt;$dateto,
    'freetext'=&gt;$freetext,
    'ada'=&gt;$ada
  ];
   

}

controller:
class DiafaneiaController extends ControllerBase {

  public $filters=[];

  public function getList(Request $request) {

    $filters = \Drupal::request()-&gt;request-&gt;all();


    $data = array();
    $response = $data = $result = null;

    $page = pager_find_page()+1;
    //echo 'pageNo:'.$page;

    if (function_exists('diafaneia_reponse')) {
      $response = diafaneia_reponse('https://diafaneia.hellenicparliament.gr/api.ashx?q=documents&amp;pageSize=20&amp;pageNo='.$page.'&amp;sector=0216896c-4d26-49de-b896-a2b600ab3843', 'GET',$filters);
    }


    if ($response) {

      $result_docs = json_decode($response);
      $data = array();

      // # add all the data in one multiple dim array
      $data['title'] = 'products to consume REST API';
      $data['docs'] = $result_docs;

$num_per_page = 10;
$offset = $num_per_page * $page;

// Now that we have the total number of results, initialize the pager.
pager_default_initialize($result_docs-&gt;TotalRecords, $num_per_page);

$render = [];
$render[] = [
  '#theme' =&gt; 'diafaneia_list',
  '#data' =&gt; $data,
  '#type' =&gt; 'remote',
];


$render[] = ['#type' =&gt; 'pager'];

    }
    return $render;
  }
It's unclear how both pieces of code are connected with each other.
If you are handling the form values in form submit you need to pass the resulting parameters to the controller:
public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  // prepare $params
  $form_state-&gt;setRedirect('route_to_controller', [], ['query' =&gt; $params]);
}

If you are pointing the form action to the controller
$form['#action'] = Url::fromRoute('route_to_controller')-&gt;toString();
$form['#method'] = 'get';

then there is no form submit and you have to process the submitted values in the controller.