Drupal - Redirect user after node add/edit

You can use hook_form_alter to add a custom submit handler where you can set the redirection path.

See the FAPI for more details about form redirection.


You can create a rule that redirects the user to any page when they create or edit a specific content type. When you add a rule select "After Creating New Content" add also a condition of "Content Has Type". You Do section will give you the option to redirect a user to any page you want.

For a redirect after editing a node, just create a new rule and select "After updating Existing Content" as your first option.


When doing this, ensure to also unset a possible existing destination which normally is added to the URL when you click the edit button to edit an existing node.

Replace article in MYMODULE_form_article_node_form_alter with your content type's machine name.

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function MYMODULE_form_article_node_form_alter(&$form, &$form_state, $form_id) {

  $form['actions']['submit']['#submit'][] = '_MYMODULE_node_form_redirect';
}

/**
 * Submit callback.
 */
function _MYMODULE_node_form_redirect($form, &$form_state) {

  // Unset destination first.
  unset($_GET['destination']);
  unset($_REQUEST['edit']['destination']);

  $form_state['redirect'] = 'FOO/BAR';
}

Tags:

7

Redirection