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(&$form, &$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(&$form, &$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->disableRedirect();
}
But it's still not working.