0

I am having a problem trying to get the user to redirect to their profile page (user/uid) after they update their profile (user/uid/edit), I don't want them to remain on the page they just edited. I have looked high and low on drupal answers, google, and the documentation I can't get this to work.

Here is the code;

function form_redirect_form_alter(&$form, &$form_state, $form_id) {

    global $user;
    switch ($form_id) {
         case 'uprofile_node_form':
             $form_state['redirect'] = 'user/'.$user->uid;
             break;
    }
}

I have tried everything including a submit_handler and that doesn't work. I have tried including the base_url - doesn't work either. What am I overlooking. I figure that this should work.

I read somewhere online that redirects will not work if $form_state['storage']['values'] is not empty. If this is the problem, how would I overcome it?

Thanks.

1

There were a bunch of issues with your example, but this should work:

function YOURMODULE_form_alter(&$form, $form_state, $form_id) {

  switch($form_id) {

    case 'user_profile_form':

      $form['#redirect']='user/' . arg(1);
      break;

    // any other forms here

  }

}

which will redirect to the user page of the user being edited after editing that user. This way, if an admin is editing another user, it redirects to that user's page, not that of the logged in admin.

  • Thanks that did it! I did try using form['#redirect'] as well similar to what you have (except using user->uid) but it didn't work for me - I must have missed something. Thanks again. – user5013 Aug 29 '12 at 20:35

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.