1

I am building a module on drupal 8 to make a redirection after a form is submitted

function form_redirect_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    $form['actions']['submit']['#submit'][] = 'ptt_contact_form_blocks_submit';
}


function ptt_contact_form_blocks_submit($form, FormStateInterface $form_state) {
    $form_state->setRedirect($route_name);
}

but for the setRedirect, it needs to have the route name. Like if i want to redirect to node/24, then how can i find the route name of the node?

Thanks!

marked as duplicate by kiamlaluno Jun 1 '16 at 14:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

check this one

function ptt_contact_form_blocks_submit($form, FormStateInterface $form_state) {
    $form_state->setRedirect('node/24'); // node/$node->nid
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.