We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38846
    • 30 Posts
    I have found a few post that ask similar questions but no answer yet.

    User is on page 2 and wants to login. No problem I redirect to login page and the user logs in. Then once logged in I want to redirect to whatever page the user was redirected to the login page from, in this case page 2, but it could be any.

    Any idea how I would accomplish this?




      • 3749
      • 24,544 Posts
      In the Login snippet tag:

      &redirectToPrior=`1`


      I'm not sure if this works in Evolution or not, but it should in Revo.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38846
        • 30 Posts
        Once again sir you are of incredible help!
          • 38846
          • 30 Posts
          I think this has something to do with me working on a Local MAMP server, because it is not working. I found a earlier post you were discussing this with someone and you told them how to test it. Using that snippet:
          <?php
          return 'Prior Page URL: ' . $_SERVER['http_referer'];


          returns an error that the page is not defined. I also tried storing the value in view state like this with the same resultant error:
          <?php if( !IsPostBack ) { ViewState["PreviousPageUrl"] = Request.UrlReferrer.ToString(); };


          Any ideas how I can send the user back to the referring page after login? Other than a drop down login, which i guess could be a solution.
            • 36404
            • 307 Posts
            hi,

            don't know if it's the best solution but you could store the current page in a cookie when someone clicks on the login link and then retreive the value when you user is logged and send him back to the "referer page"

            another way (same kind of solution as your dropdown menu) would be to use the login form in a modal box (of course, keeping a standolone login page for the rare ones coming without js)
            actually it's often the solution i go for... just having the modal box refresh its parent on closing to be able to display the logged user infos

            have swing
              réfléchir avant d'agir
              • 38846
              • 30 Posts
              CookieList could work, I guess.

              I just didn't figure it being that difficult.

              It is a pain when someone wants to add a product to their wishlist and has to login and then re-navigate back to the product page they wanted to add. Otherwise I would be fine with it. I also thought about leaving them on the login page and just offering to go back to the previous page, which is the most secure way of doing it, but that would require cookielist as well. So I guess either way....
                • 3749
                • 24,544 Posts
                You could also use a $_SESSION variable. FYI, &redirectRoPrior won't work if you type or paste in the Login URL, you have to get there by clicking on a link and it might also not work if you're previewing from the Manager or are logged into the Manager in another window of the same browser.

                You may be right, though about your MAMP server not setting the referrer.


                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 38846
                  • 30 Posts
                  Yea I was making sure to clear cache and work through it like a new user would so that takes the pasting url and logged into the manager out of the question. It has to be either firefox or MAMP, which is fine. I realize this is not the most secure way to do things but in the end a boss wants functionality and it is my/your (lol) job to figure out how.

                  I did notice on the forums here it doesn't redirect you to the last page when you login but it does however hold your login credentials even if you hit the back button. That might be a solution. When I try it on the site i am creating I lose login credentials when hitting the back button. How are they doing it here?
                    • 3749
                    • 24,544 Posts
                    I don't know, but I do sometimes see problems on localhost that disappear on the remote site.


                    ------------------------------------------------------------------------------------------
                    PLEASE, PLEASE specify the version of MODX you are using.
                    MODX info for everyone: http://bobsguides.com/modx.html
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 43957
                      • 79 Posts
                      I know this is an old post, but I have a similar redirect issue I'm trying to overcome with Cookielist, so hope this is the appropriate place to air my problem.

                      I have a store where I'm using cookielist to add items to the basket. I also want to have a 'buy it now' button to add the item to cookeList and then redirect to the basket page.

                      cookielist doesn't have a &redirectTo parameter and I think that would be the best way to solve the problem. Maybe it is for the login scenario too?

                      This is what I'd like to do in my call:

                      [[!addToCookieList?
                      &tpl=`chnk_addtoBasket_Button`
                      &addText=`Buy it Now`
                      &redirectTo=`123`
                      ]]


                      Here's a segment of the code from cookieList plugin

                      if($addValue || $removeValue) {
                          $error = (isset($c['cl_check'])) ? false : true;
                          $url = $cookielist->url($error);
                          // Creates/updates the cookie and its value
                          $value = implode(',', $cookieValues);
                          $duration = time() + $modx->getOption('cookielist.cookie.duration',null,2592000);
                          setcookie($cookieName, $value, $duration, '', false, false);
                          $modx->sendRedirect($url);
                      }


                      Now, I think somewhere in here I can pull in the redirectTo parameter to:

                      $url = $modx->makeUrl(redirectURL);


                      So, I want to makeUrl if &redirect para is populated.

                      Any help with my coding would be greatly appreciated. If I figure it out, I'll post my code.