Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Submit Registration and Redirect


  • Nahum
    Participant

    @nahummadrid

    Trying to pass some input info over to another form right after full registration that users need to fill out before being able to login to the site. The email and username are sent over to sync accordingly. I’ve gotten this far…but I guess the redirect cancels the form submit and the wp user needs to exist so they can login after the 2nd external form. Any suggestions on how to ensure the form gets submitted before redirecting to the external url?

    
    <script type="text/javascript">
    
    $(function() {
        $('form#signup-form').submit(function (e) {
            e.preventDefault();//prevent the default action
    
            $.ajax({
                type: "POST",
                /*url:*/
                /* data:*/
                success: function (msg) {
    
                    var name = jQuery('#signup_username').val();
     				var email = jQuery('#signup_email').val();
     				var queryString = "https://xxxxxx.com?username2=" + name + "&email2=" + email;
    
    				window.location.replace(queryString);
    
                },
                error: function () {
                    alert("error");
                }
            });
        });
    });
    
    </script>
Viewing 3 replies - 1 through 3 (of 3 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    function ps_bp_redirect($user) {
        $redirect_url = 'your_url_here';
        bp_core_redirect($redirect_url);
    }
    
    add_action('bp_core_signup_user', 'ps_bp_redirect', 100, 1);

    Please try this snippet.

    Thanks


    Nahum
    Participant

    @nahummadrid

    Thanks for the suggestion, I think I tried that and my problem there was getting what the user inputted username and email to add to the url in order to prepopulate the next form on the redirected page. I can’t auto log them in quite yet to get current user info.

    What I ended up doing was this with a plugin:

    <script src="http://malsup.github.com/jquery.form.js"></script> 
    
        <script> 
            // wait for the DOM to be loaded 
            jQuery(document).ready(function($) { 
                // bind form and provide a simple callback function 
                $('form#signup-form').ajaxForm(function() { 
    
                    //window.location = "/page/success" 
    
                   var name = jQuery('#signup_username').val();
                   var dname = jQuery('#field_1').val();
                   var email = jQuery('#signup_email').val();
     	       var city = jQuery('#field_2').val();
    
     	       var queryString = "https://______.com?username=" + name + "&email=" + email + "&firstName=" + dname + "&address.city=" + city;
    
    		window.location.replace(queryString);
    
                }); 
            }); 
        </script>

    on the register page. I’d rather go with your suggestion and expand on it to make this work with a snippet behind the scenes.


    Prashant Singh
    Participant

    @prashantvatsh

    function ps_bp_redirect($user) {
        $redirect_url = 'your_url_here';
        wp_safe_redirect( add_query_arg( array( 'user' => $_POST['signup_username'] , 'email'=> $_POST['signup_email']), $redirect_url ) );
    }
    add_action('bp_core_signup_user', 'ps_bp_redirect', 100, 1);

    This code will add query parameters in the URL itself, from there try to fetch it in javascript https://davidwalsh.name/query-string-javascript

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar