3

Is there any way to redirect the user after save their profile information.

I would like to redirect them to a specific page.

To be clear, here is the Flow:

  1. User go in his profile
  2. He change his password information
  3. The user click on Save Button
  4. The information is save and I want to redirect him on a specific page (node/xxx)
1
3

You can add a custom submit handler to the user edit form and then do the redirect there:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id === 'user_profile_form') {
    $form['#submit'][] = 'custom_submit_function';
  }
}

function custom_submit_function($form, &$form_state) {
  drupal_goto('node/xxx');
}
3

Here's the code for Drupal 8 :

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id === 'user_form') {
    $form['actions']['submit']['#submit'][] = '_mymodule_user_edit_form_submit';
  } 
} 
function _mymodule_user_edit_form_submit($form, &$form_state) {
  $form_state->setRedirect('entity.user.canonical', ['user' => \Drupal::currentUser()->id()]);
} 
1

You can achieve it by rule , create a rule then redirect to a url after user update I create it for you, just change the url and import it

Go to admin/config/workflow/rules/reaction/import and import this url ( first change the url , I set it to jean-fransico :) )

{ "rules_redirect_after_user_update" : {
    "LABEL" : "redirect after user update",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_update" : [] },
    "DO" : [ { "redirect" : { "url" : "Jean-Francois" } } ]
  }
}

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.