Prevent redirection after comment submission When a user add a comment on a node, I would like to prevent the page reload.

I added a form_alter in my theme

function theme_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    switch($form_id) {
      case 'my_form_id':
        $form_state['redirect'] = false;
      break;
  }
}


But this is not working.

I also tried to replace $form_state['redirect'] = false by $form_state['redirect'] = false but it seems to be the Drupal 7 way to do this.

how could I achieve that on Drupal 8 ?

EDIT

I tried to use a submission handler

function theme_form_alter(&amp;$form, &amp;$form_state, $form_id) {
        switch($form_id) {
          case 'my_form_id':
            $form['#submit'][] = 'theme_form_submit';
          break;
      }
    }

function theme_form_submit(array $form, FormStateInterface $form_state){
    $form_state-&gt;disableRedirect();
}


But it's still not working.
Use FormStateInterface::disableRedirect(), e.g.

$form_state-&gt;disableRedirect();


Make sure you run that code in a submit handler for the form, not in the form alter hook.