Using Login Widget Have User Stay On Same Page

Discussion in 'aMember Pro v.4' started by jld1370, Jul 8, 2013.

  1. jld1370

    jld1370 New Member

    Joined:
    Aug 12, 2012
    Messages:
    18
    I'm using an aMember text widget on a Wordpress sidebar for member logins.

    When the users log in, they go to the fixed URL that I outline in the aMember admin console, but I would really like to have the user log in with the widget and have the user stay on the same page they were on, only with the protected content visible.

    For example, a post may have the following structure:

    Introduction to the post that everybody can see
    [am4show have='my product/categories']
    protected content that only members can see when logged in
    [/am4show]

    Right now, the user goes to that post and isn't logged in. He reads part of the post, then logs in using the widget, then he gets dumped to a different page on the site, and has to navigate back to the post he was reading.

    Ideally, I'd like the user to read the post, login, and have the page reload with the protected content now visible.

    How can I make this happen?

    Here is the code I'm using for the login widget:
    <form action="/members/login" method=post>

    Username:
    <input type=text name=amember_login size=35><br>

    Password:
    <input type=password name=amember_pass size=35><br>

    <input type=submit value=Login>
    </form>
  2. gswaim

    gswaim CGI-Central Partner

    Joined:
    Jul 2, 2003
    Messages:
    641
    I would try the aMember Widget that is designed for logging in instead of a the aMember text widget. See if you like its behavior any better.
  3. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    You need to add something like this into that widget/form:

    <input type="hidden" name="amember_redirect_url" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
  4. jld1370

    jld1370 New Member

    Joined:
    Aug 12, 2012
    Messages:
    18
    @ Grant - I gave that a try and it didn't work as well.

    @ miso - you nailed it. I changed the widget, and added that line to the top.
    I also removed the value in "fixed URL" for redirection in the aMember control center.
    Now when users log in with the widget, they go to their member page. A quick edit to the message telling them to hit the back key to return makes it work well.

    Thank you both for the quick replies!

    J


    Here's the new form:
    <input type="hidden" name="amember_redirect_url" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />

    <form action="/members/login" method=post>

    Username:
    <input type=text name=amember_login size=35><br>

    Password:
    <input type=password name=amember_pass size=35><br>

    <input type=submit value=Login>
    </form>
  5. jld1370

    jld1370 New Member

    Joined:
    Aug 12, 2012
    Messages:
    18
    Of course, the simplest solution eluded me...

    To make it a little nicer, I created a "Welcome Back" page on the site, with a simple javascript link to go back to their content.

    In aMember control center I added that page link as the fixed URL, and now users go to my welcome page.

    Here's the code for that:
    <a href="javascript:history.back()">Click here to go back to where you left off</a>

Share This Page