2

I have a component, which requires login. I added a text about this to the components main page. Is there a way to redirect the users to the component after they logged in? Currently all they see is the profile page and they have to find the menupoint again after they logged in.

2

You can create a plugin that triggers on onUserAfterLogin and redirects the user to where you want.

or you can add a &return= query variable to your links to the login page as described here

  • Creating a plugin to have this behavior in a component does not sound right. I'll try the other solution with the return param. I hope it works with this Joomla version. – inf3rno Mar 21 '17 at 18:55
  • The plugin method would give you more control and be easier to manage. Ie, you can change the redirect link by tying it to a parameter of the plugin and you can disable the redirect by disabling/unpublishing the plugin. – Drew G Mar 21 '17 at 19:23
  • 1
    For the &return= method, you can, if you want, give it just the menu ID of the menu item you want to redirect the user to (needs to be base64 encoded still though). Eg, if you want to redirect to menu item 34 you can set '&return=' . base64_encode(34) and it should work. – Drew G Mar 21 '17 at 19:28
  • Actually I have a component, which I can reach through a menu point. Without login it writes a text, that you have to login. I'd like to add a login link to that page and I'd like the users to be redirected to the same page after they logged in. So I don't want them to be always redirected after login, just when they used the link. Or if there is a way to add a login form that would be okay as well. Hmm actually I can write one if necessary. Not a big deal, but it would be nice to reuse the default login form Joomla provides. – inf3rno Mar 21 '17 at 20:07
  • 1
    You might be able to do something like what you're describing (I've not done something like that though). Consider a different route that is similar: Instead of giving them a message to log in with a link you could have your component redirect them to the com_user login page (with the &return= query set). You can then override the com_user login page (by creating /ROOT/template/<tpl name>/html/com_users/default_login.php) to make it look the way you want. Or, if you don't want to override the default login page create default_loginwhatever.php and have the component redirect to that layout. – Drew G Mar 21 '17 at 20:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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