How to create a search box bloc with search API I'm using Drupal 8 and i've installed search API and Search API Solr Search.

I followed this great tutorial

How can I display a search box on all of the pages of my website ?
Although you can expose the views form as a block and you can add it twice to a page, the issue is that you may just want a keyword search form in the header but on the actual form you want something more. An additional peculiarity was that the infinite scrolling plugin makes the form ajax, and when exposed as a block it fails to submit.

My solution was to create a new form + block and place the block it where I needed it:


my_search.module:

&lt;?php
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter() for the search_block_form form.
 */
function my_search_form_header_search_alter(&amp;$form, FormStateInterface $form_state) {
  // NB so that these are not added to the get query params
  $form['form_build_id']['#access'] = FALSE;
  $form['form_token']['#access'] = FALSE;
  $form['form_id']['#access'] = FALSE;
}


HeaderSearch.php:

&lt;?php

namespace Drupal\my_search\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Class HeaderSearch.
 *
 * @package Drupal\my_search\Form
 */
class HeaderSearch extends FormBase {


  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'header_search';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $form['#action'] = '/search';
    $form['#method'] = 'get';
    $form['k'] = [
      '#type' =&gt; 'search',
      '#title' =&gt; $this-&gt;t('Keyword'),
      '#maxlength' =&gt; 64,
      '#size' =&gt; 15,
      '#title_display' =&gt; 'invisible',
    ];

    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Search'),
      // Prevent op from showing up in the query string.
      '#name' =&gt; '',
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    // Form is redirected no need for anything here.
  }
}


MySearchBlock.php:

&lt;?php

namespace Drupal\my_search\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'MySearchBlock' block.
 */
class MySearchBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    return \Drupal::formBuilder()-&gt;getForm('Drupal\my_search\Form\HeaderSearch');
  }

}