PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

User registration > login > redirect to private page

  1. twistystraws
    Member

    Hi

    I'm fairly certain this can be done, but need a pointer in the right direction, as I'm only just learning the ropes...I want to set up a user registration form, that when completed logs the user in, and then redirects them to a subscriber only page? If anyone tries to access that page they'll be presented with the login form.

    Sounds simple enough. I've created the form which successfully registers the user, but how do I get them to be logged in? I want to negate the need for them to enter the wordpress admin/backend...

    Thanks in advance.

    Posted 13 years ago on Monday April 4, 2011 | Permalink
  2. danielpettifer
    Member

    Are you looking for something like this? http://wordpress.org/extend/plugins/weasels-login-redirection/

    Posted 13 years ago on Monday April 4, 2011 | Permalink
  3. Gravity Forms User Registration Add-On doesn't currently automatically login the user after they register. It is a feature we plan on adding in a future release. The Add-On is a 1.0 release and is brand new so there are a lot of features we plan on adding in future releases.

    Posted 13 years ago on Monday April 4, 2011 | Permalink
  4. Any more or less ETA on this feature? I'm building something like this for a client, and wanna make sure I'm not working for nothing if you are going to build this in a few weeks :)

    Cheers

    Posted 13 years ago on Wednesday April 20, 2011 | Permalink
  5. Hi Jkudish,

    Your efforts won't be in vain. This feature is not planned in the time frame you've specified.

    Posted 13 years ago on Wednesday April 20, 2011 | Permalink
  6. Cool, thanks for the quick reply :)

    Posted 13 years ago on Wednesday April 20, 2011 | Permalink
  7. Hi Jkudish,

    Any luck on adding this feature yourself ? Do you have any pointers ?

    Posted 12 years ago on Friday May 6, 2011 | Permalink
  8. Can you recommend a plug-in for this feature that works well with Gravity forms while you are working on this improvement? I need a plug in for login that uses the data from Gravity Forms User Registration Add-On.

    Posted 12 years ago on Wednesday May 18, 2011 | Permalink
  9. blrfurther
    Member

    Give this a try

    http://www.pastie.org/1990358

    Posted 12 years ago on Sunday May 29, 2011 | Permalink
  10. sascha
    Member

    Did anyone get any further with this? Does the code from "blrfurther" work? Where would I put it if it does? Many thanks!

    Posted 12 years ago on Wednesday August 3, 2011 | Permalink
  11. @sascha, I have not tried it, but if you would like to try it, you add that code to your functions.php.

    Instructions on where to put the code:
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 12 years ago on Wednesday August 3, 2011 | Permalink
  12. sascha
    Member

    Hi Chris,
    put that code from blrfurther into the function.php but nothing happens. Where do these two lines get their information from exactly (that might be the problem - depanding where my fields are in the form?!?):
    $user_login = $_POST['input_1']; //use the input if of the username
    $user_pass = $_POST['input_2']; //use the input if of the password

    What is input_1, input_2 etc. Do I find that in the documentation or on the from itself?

    Posted 12 years ago on Wednesday August 10, 2011 | Permalink
  13. Those are from your specific form. If you post a link to your form, I can help you find those IDs. Otherwise, just look at the source of a page where your form is embedded and find the username and password fields, for your form, and change these values to those values from your actual form.

    Posted 12 years ago on Wednesday August 10, 2011 | Permalink
  14. hi

    I try to use this code but it's not working

    add_action("gform_user_registered", "register_login_reload", 10, 1);
    
    function register_login_reload($user_id, $config, $entry) {
        $user_login = $_POST['input_1']; //use the input if of the username
        $user_pass  = $_POST['input_4']; //use the input if of the password
    
        //pass the above to the wp_signon function
    
        $user = wp_signon( array(	'user_login' => $user_login,
        					'user_password' =>  $user_pass,
        					'remember' => false
        			   )
        		);
    Posted 12 years ago on Monday August 22, 2011 | Permalink
  15. Hi All

    Many thanks for posting the code above. I am also looking for a user to be logged in automatically after completing the registration.

    I tried adding the code from the Pastie link to my functions.php page. I amended the input ids based on the form on the page but nothing different happened. I have no page redirect after the registration form, I did not add any additional code to the page the form is on other than the gravity forms code. I am wondering if I am missing something.

    I would paste the URL etc, but its private page in development with a username and password that I can't post. I would be happy to send these by email to support if that were needed.

    Many thanks for any help / advice you can offer on this issue.

    Regards
    Mike

    Posted 12 years ago on Wednesday August 24, 2011 | Permalink
  16. The original redirection set in the register form will not work after this code is executed. In fact it will use the redirect behaviour after the user is logged in. The code is working quite nicely.

    Posted 12 years ago on Monday September 19, 2011 | Permalink
  17. jeffreygaudette
    Member

    I am also interested in a solution to auto login a user after form completion. Any idea on completion date since we're now at version 1.2.9?

    I have multiple registration forms that redirect to specific welcome pages, which give users the content they need. If they try to login from this page, they are redirected to the homepage, which means they can't get the information they need. If the user was already logged-in and directed to the welcome page by the form, it would work perfect.

    Thanks!

    Posted 12 years ago on Wednesday November 2, 2011 | Permalink
  18. You can handle the redirection in your page template. I don't see any links to your site to know exactly how it should work in your case, but you can check in the page template if they're logged in, and if so, send them one place. If they're not, show them the login form.

    I used code like this:

    [php]
    <?php
    /*
    Template Name: Must log in
    */
    if(!is_user_logged_in()) {
        $siteurl = get_bloginfo('url');
        $request = $_SERVER['REQUEST_URI'];
        $redirect = urlencode($request);
        header("Location: $siteurl/wp-login.php?redirect_to=$redirect");
        exit;
    }
    get_header(); ?>
        <div id="content">
           your content here
        </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    This does not automatically log anyone in after registration, but it does handle directing them where they need to go, logged in or not.

    I have seen a couple threads on wordpress.stackexchange.com about automatically logging users in after registration, but I've never spent enough time on one to get it to work reliably.

    Posted 12 years ago on Wednesday November 2, 2011 | Permalink
  19. jeffreygaudette
    Member

    Thanks, Chris. Unfortunately, that doesn't work in my case and doesn't solve the issue. I do already have a redirect code in the functions.php that redirects users once they are logged in through the normal login process.

    My issue is that I have specific welcome areas that each registered member type needs to go to after they signup. If the user isn't logged in during the registration process, they can't see protected content (if I wanted to include it on this page) and I can't give them steps to perform member restricted actions. I hope that further clarified my need for auto-login after registration.

    Thanks for the help.

    Posted 12 years ago on Wednesday November 2, 2011 | Permalink
  20. blrfurther
    Member

    Sorry folks, I have not received any updates on this thread. I can assist anyone wanting top get this done.

    //login after registration
    add_action("gform_user_registered", "register_login_reload", 10, 3);
    
    function register_login_reload($user_id, $config, $entry) {    
    
    	$user = new WP_User($user_id);
    
        $user_login = $_POST['<your username input>']; //use the input of the username in your form
        $user_pass  = $_POST['<your password input>']; //use the input of the password in your form
    
        //pass the above to the wp_signon function
        wp_signon( array(	'user_login' => $user_login,
        					'user_password' =>  $user_pass,
        					'remember' => false
        			   )
        		);
    
        $user = get_userdata($user_id);
    
       	wp_redirect( get_bloginfo('url').'/<where you want to redirect>');
    
    	}
    
    Use the wp_redirect at the end of the code to redirect. Change the items inside <> to your specific site's needs.

    @bigflannel congrats on the writeup in SlideShowPro's news!

    Posted 12 years ago on Thursday November 3, 2011 | Permalink
  21. Is there a way to get the GravityForm generated password to allow auto login ?

    Posted 12 years ago on Friday November 4, 2011 | Permalink
  22. Danny
    Member

    Here is a simple working solution for this. Tested and working with GF 1.6. This will work for any registration form out of the box.

    Simply set up what page you want to redirect to in the form options and then add the below code to your theme's functions.php file (this will take care of the auto login).

    add_action( 'gform_user_registered', 'pi_gravity_registration_autologin', 10, 4 );
    /**
     * Auto login after registration.
     */
    function pi_gravity_registration_autologin( $user_id, $user_config, $entry, $password ) {
    	$user = get_userdata( $user_id );
    	$user_login = $user->user_login;
    	$user_password = $password;
    
        wp_signon( array(
    		'user_login' => $user_login,
    		'user_password' =>  $user_password,
    		'remember' => false
        ) );
    }
    Posted 12 years ago on Friday November 4, 2011 | Permalink
  23. dimensionmedia
    Member

    Danny, i tried your code and it doesn't seem to be picking it up (seems to ignore it). So strange why it's ignoring the gform_user_registered hook there. The code is in functions.php. Any ideas?

    Posted 12 years ago on Thursday November 10, 2011 | Permalink
  24. Thank you Danny. It works great. Just what I needed to make my client happy!!

    Posted 12 years ago on Thursday April 12, 2012 | Permalink
  25. Andrew Munro
    Member

    Thanks Danny, worked great over here too :)

    Posted 11 years ago on Monday April 30, 2012 | Permalink
  26. David Peralty

    I'm going to close this for now to keep support needs clean. :)

    Posted 11 years ago on Monday April 30, 2012 | Permalink

This topic has been resolved and has been closed to new replies.