Skip to content

Instantly share code, notes, and snippets.

@henryhu712
Created April 11, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryhu712/842f0fafe692dab93a650fa9c6a40c83 to your computer and use it in GitHub Desktop.
Save henryhu712/842f0fafe692dab93a650fa9c6a40c83 to your computer and use it in GitHub Desktop.
Redirect form submit on Drupal 7

In hook_form_alter(), there are 2 methods:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_pass') {
    $form['#submit'][] = 'reflesh_current_path';
  }
}
function reflesh_current_path($form, &$form_state) {
  $current_path = current_path();
  $form_state['redirect'] = $current_path;
}

The second is to replace one line with:

$form['actions']['submit']['#submit'][] = 'reflesh_current_path';

But, the second will lost all messages!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment