Each user has a "Edit" tab/button on their profile. They click it, edit their profile, and when it is saved, they are kept on that page. I want the user to be taken back to his/her "View" or profile page.


6 Answers 6


As @Aboodred, if you already have the Rules module installed, adding a simple rule can do the job.

  1. Create a rule with the React on event type After updating an existing user account.

  2. Add a Page redirect action. Set the 'Data selector' field to account:url (either manually or using the dropdown).

enter image description here

  • 1
    This worked @obliquely! Many thanks (and to @Aboodred1 too).
    – Big Robots
    Commented Mar 2, 2013 at 20:09

If you want to do it with code instead of rules you can take a look at how the user_edit_cancel_submit function does it in user.pages.inc.

First you define an submit function: $form['#submit'][] = 'custom_redirect_after_save';

Then you add the function:

function custom_redirect_after_save($form, &$form_state) {
  if (isset($_GET['destination'])) {
  $form_state['redirect'] = array("user", array());

In Drupal 8/9:

 * Implements hook_form_FORM_ID_alter().
function MYMODULE_form_user_form_alter(&$form, &$form_state) {
  // Redirect users to their profile pages.
  $form['actions']['submit']['#submit'][] = 'MYMODULE_user_edit_form_submit';

 * Redirect users to their profile pages when submitting the edit form.
function MYMODULE_user_edit_form_submit($form, &$form_state) {
  $form_state->setRedirect('entity.user.canonical', ['user' => \Drupal::currentUser()->id()]);

You can add additional submit function to user_profile_form by using hook_form_alter to return back to profile page after editing user profile.

Your code should look like the following:

function MODULE_NAME_form_user_profile_form_alter(&$form, $form_state, $form_id) {
  $form['#submit'][] = 'MODULE_NAME_user_profile_form_submit';

function MODULE_NAME_user_profile_form_submit($form, &$form_state) {
  global $user;
  drupal_goto('user/' . $user->uid);
  • 1
    You don't need to do a drupal_goto because you can use a $form_state['redirect'] instead. See the answer from @andeersg.
    – jenlampton
    Commented Mar 25, 2016 at 1:10
  • @JenLampton all roads lead to Rome :D
    – Aboodred1
    Commented Apr 3, 2016 at 6:39
  • @Aboodred1If you use drupal_goto you cut off every other submit function or alter hooks. If you set the redirect key in the form_state all the submit functions will execute before redirecting.
    – andeersg
    Commented Aug 15, 2016 at 11:24

On my system (Drupal 6) it was

1) Install Rules Module:


2) Activate Rules Module in Administration Console

[site url]/admin/build/modules (Look for a new Module category called Rules)

3) Enable the following Module(s):

Rules Administration UI 6.x-1.5 Provides the administration UI for rules. Depends on: Rules (enabled)

Rules Forms support 6.x-1.5 Provides events, conditions and actions for rule-based form customization. Depends on: Rules (enabled)

Rules Scheduler 6.x-1.5 Schedule the execution of rule sets. Depends on: Rules (enabled)

4) Navigate to Rules area and configure the rule:

Rules | Triggered Rules | Add a new rule

....fill in as per Obliquely's instructions...

BUT - There was no DATA SELECTOR or dropdown.

Instead I had to fill it in by hand, which was easy:

To: [account:account-url]


It worked in Drupal 8

use Symfony\Component\HttpFoundation\RedirectResponse;

function YOUR_MODULE_user_update($account) {
  $uid = \Drupal::currentUser()->id();
  $url = '/u/' . $uid;
  $response = new RedirectResponse($url);
  $request = \Drupal::request();
  \Drupal::service('kernel')->terminate($request, $response);
  • This is a bad answer because terminating the kernel early while in a hook means that no other hook will get a chance to operation.
    – anonymous
    Commented Jul 25, 2021 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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