0

We have a link on our site which will redirect users to the edit profile page when they are logged in.

We have same link for the anonymous users which will redirect the user to login page when it clicked.

We would like to redirect users to the edit profile page after login but if users use normal login link, after login, they are redirected to the homepage.

I would like to know how we can redirect users to edit profile page after login only if they clicked on the edit profile link.

1

2 Answers 2

1

In Edit Profile link append destination parameter like:

if(user_is_anonymous()){    
  $editlink = l(t('Edit Profile'), 'user/login', array('query' => array('destination' => 'user/UID/edit')));
}

Then after login, it will redirect to profile edit page.

4
  • When I use this as Edit Profile link, it will redirect users to a blank page ! it should redirect to login page : example.com/user !
    – Sinf
    Nov 17, 2016 at 9:15
  • Try changing url values, above one is working for me in one of my project. add user_is_anonymous condition
    – Ajay Reddy
    Nov 17, 2016 at 9:56
  • Thx, now I have another problem ! how can I get UID after user login ? if not, it will not redirect to user edit profile ! it just show access denied ! I need something like : user/xxx/edit which xxx is the logged user UID.
    – Sinf
    Nov 17, 2016 at 11:30
  • Do one thing, change destination to your custom URL like "user-edit" and in user-edit call back redirect to "user/UID/edit" . TO get UID, global $user; $uid = $user->uid; For access denied "give permissions" to user, to edit their own profile.
    – Ajay Reddy
    Nov 17, 2016 at 11:33
0

There are different ways to do this, refer this https://www.drupal.org/node/683696

2
  • Please read my question again ! there is some conditions ! I already saw that of course before asking this question !
    – Sinf
    Nov 17, 2016 at 9:05
  • are you trying to do this with a custom module?
    – ana
    Nov 17, 2016 at 9:59

Your Answer

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

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