How to redirect a user in Drupal after node add/edit?

I want to redirect a user to a specific page after one edits a node.

Stephen Bell Asked on October 21, 2015 in Drupal.
Add Comment
1 Answer(s)
Best answer

You can easily redirect a default form after add/edit. In order to achieve this, you can make use of a redirection function. Here I will explain how to redirect a node edit form to a custom page called ‘TargetPage’. Just take a look at the following easy steps to do that:

• Create a hook_form_alter function.
• Add a submit function as the following one

function moduleName_form_alter(&$form, &$form_state, $form_id) { if (($form_id == 'your_form_id') && (arg(2)=='edit')) { $form['actions']['submit']['#submit'][] ='hook_node_edit_custom_submit'; } }

• Finally define the custom submit handler

function moduleName_node_edit_custom_submit($form, &$form_state) { unset($_GET['destination']); unset($_REQUEST['edit']['destination']); $link = 'TargetPage'; $form_state['redirect'] = $link; }

James Flynn Answered on October 21, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.