4

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.

3

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

| improve this answer | |
  • 1
    This worked @obliquely! Many thanks (and to @Aboodred1 too). – Otter Creative Studio Mar 2 '13 at 20:09
3

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'])) {
    unset($_GET['destination']);
  }
  $form_state['redirect'] = array("user", array());
}
| improve this answer | |
0

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);
}
| improve this answer | |
  • You don't need to do a drupal_goto because you can use a $form_state['redirect'] instead. See the answer from @andeersg. – jenlampton Mar 25 '16 at 1:10
  • @JenLampton all roads lead to Rome :D – Aboodred1 Apr 3 '16 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 Aug 15 '16 at 11:24
0

On my system (Drupal 6) it was

1) Install Rules Module:

https://www.drupal.org/project/rules

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]

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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