Automatic redirect to custom page after signup

Discussion in 'Customization & add-ons' started by mike_mac, Apr 11, 2016.

  1. mike_mac

    mike_mac aMember Pro Customer

    Joined:
    Jan 21, 2010
    Messages:
    9
    I use amember as the member management software for my office pool site, www.myofficepool.ca. The site allows people to join or create their own office pools. Each pool has its own unique URL.

    If I add the amember_redirect_url to the login link anywhere on the site then I can get people automatically redirected back to the pool they want to join after logging in. Works like a charm.

    What I want is to do the exact same thing after a new member registers for the first time. Pulling my hair out with this one.

    Note there are no products on the site currently other than a free membership. Although I customized a thank you page I want newly registered users to skip this page entirely and go right back to the pool they clicked register from. Otherwise they will have a harder time finding the pool again.

    I've looked through the SignupController, the ThanksController, etc. I can get the redirect URL into the sign up form. Cannot seem to find how to get the redirect to trigger if that redirect URL is set as opposed to the thanks.phtml page. Any help here would be greatly appreciated.
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Here is one solution that I can see:

    1. add new user field (call it redirect, and make field SQL) at
    aMember CP -> Configuration -> Add User Fields

    2. add this new field to sign up form (configure it and make this field hidden)
    aMember CP -> Configuration -> Forms Editor

    3. pass variable redirect to your form url eg.
    /amember/signup?redirect=/path/of/your/pool

    4. put the following code to site.php file (http://www.amember.com/docs/Site.php_file)
    Code:
    Am_Di::getInstance()->hook->add(Am_Event::THANKS_PAGE, function(Am_Event $e){
        if ($inv = $e->getInvoice()) {
            $user = $inv->getUser();
            if ($r = $user->redirect) {
                $user->updateQuick('redirect', null);
                Am_Mvc_Response::redirectLocation($r);
            }
        }
    });
    Please note code above is valid only since aMember 5
  3. mike_mac

    mike_mac aMember Pro Customer

    Joined:
    Jan 21, 2010
    Messages:
    9
    Thanks caesar. I haven't upgraded as of yet but was considering it. This may push up the decision.
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    For version 4 everything is same with exception of last step. Here is code for version 4:
    Code:
    Am_Di::getInstance()->hook->add(Am_Event::THANKS_PAGE, function(Am_Event $e){
        if ($inv = $e->getInvoice()) {
            $user = $inv->getUser();
            if ($r = $user->redirect) {
                $user->updateQuick('redirect', null);
                Am_Controller::redirectLocation($r);
            }
        }
    });

Share This Page