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.

All Users of a Role Register for Primary Site (multisite)

  1. Would it be possible to add a function that says if someone fills out the registration form for a certain role (subscriber) they are automatically signed up on the primary domain, and nowhere else?

    So... If register= 'subscriber' then site = 'primary url'

    This is technically the wordpress default, but if you put a GF user registration form on a subsite, they are placed on that site instead of the main site. Is there a way to have GF do it the standard way?

    Posted 11 years ago on Tuesday July 10, 2012 | Permalink
  2. David Peralty

    While the plugin and add-ons do work in multisite, they don't support every feature as of yet. Our user registration is site specific and as such, users will register to the site the form is on, and you can't easily change this based on user role.

    Here is where you would find all of the documentation currently available for that add-on:
    http://www.gravityhelp.com/documentation/page/User_Registration_Add-On
    http://www.gravityhelp.com/documentation/page/User_Registration_Add-on_Developer_Docs

    Posted 11 years ago on Tuesday July 10, 2012 | Permalink
  3. Okay, thanks for the reply.

    I am now just trying to setup a redirect so all register links go to the mainsite and then just redirect back to previous page. Is there a way to attach a query string or something like that for the redirect to accomplish this?

    I tried this in my function:

    <a href="http://hookahi.com/member-join?redirect_to='.get_permalink().'" rel="nofollow">Register</a>';

    but the GF redirect overrode it and sends the user to the homepage.

    Posted 11 years ago on Wednesday July 11, 2012 | Permalink
  4. David Peralty

    So you have a registration link on a page, that goes to a Gravity Form and then you want it to go back to the page that they clicked on Register from? You could grab the HTTP Referrer and put it in a hidden field. Then you have the URL to use and you can add it to this hook:
    http://www.gravityhelp.com/documentation/page/Gform_confirmation

    Posted 11 years ago on Wednesday July 11, 2012 | Permalink
  5. Thanks for that, I think that is exactly what I am looking for. I am a bit of a php noob. Can you tell what I did wrong with this:

    add_filter("gform_confirmation", "custom_confirmation", 10, 4);
    function custom_confirmation($confirmation, $form, $lead, $ajax){
        if($form["id"] == "11"){
            $confirmation = array("redirect" => wp_referer_field( $echo) );
        }
        return $confirmation;
    }
    Posted 11 years ago on Wednesday July 11, 2012 | Permalink
  6. David Peralty

    I am not well versed in what wp_referer_field should give you back, but instead of echo, can you just put it without that in it, and see if it works?

    You might also want to push the value to a variable, and test to see if it gets a value...something like

    $redirurl = wp_referer_field();
    if (!$redirurl) {
    $confirmation = array("redirect" => "http://www.google.com");
    } else {
    $confirmation = array("redirect" => $redirurl);
    }
    Posted 11 years ago on Wednesday July 11, 2012 | Permalink
  7. David Peralty

    I would have used:

    $redirurl = $_SERVER['HTTP_REFERER'];
    Posted 11 years ago on Wednesday July 11, 2012 | Permalink
  8. Hey, sorry for the late reply I must have unchecked the 'subscribe to topic'. I tried your code as well and am still getting the same result of going to the homepage or just refreshing the form. I cannot figure out what is causing this, this has been very frustrating. Query strings have failed and now hooks. It is odd that it has worked for others...

    http://wpquestions.com/question/show/id/2413 as well as all the links you've sent me. I have tried with ajax both on and off. I have tried on basic forms that are not user register forms. I am plain stuck.

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  9. David Peralty

    Sorry, with my code, it doesn't push you to Google? This is very strange. I am wondering if it is a Multisite issue? I am going to approach the dev team to see if any of them have any ideas on what could be stopping you from redirecting.

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  10. Oh no, it will redirect outside the site or static url. However, no referer or other field will work.

    Have tried:
    wp_get_referer()
    wp_referer_field()
    $_SERVER['HTTP_REFERER']
    and on and on

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  11. David Peralty

    You mentioned that Query strings failed? Can you give me more info on that? Very strange that you aren't able to redirect back to the source.. I am going to test it on my server (single install WP) and see what happens.

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  12. I am not actually sure if this is "query strings" exactly, I am still very new to code. However, this is what I meant: <a href="http://mysite.com/member-join?redirect_to='.get_permalink().'">Register</a>

    This will actually present what I believe is the right url, but whatever Gravity Forms redirect is selected in the form overrides the redirect (e.g. the confirmation message screen)

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  13. Also I wanted to thank you David for helping me out with this so far

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  14. David Peralty

    Well, I feel like this should be easy, but I'm having issues with it as well. Things aren't working the way I would expect when a variable is placed in the redirect vs a string. I'm going to talk to the developers as soon as they finish their lunch and get this sorted out.

    You can find my latest (not yet working) code here:
    http://pastebin.com/W0RcHVT1

    I know that it is grabbing the referrer URL. I know it is storing it in the array, but when I return it, for some reason, it no longer works. Once I get the last piece sorted out, I'll let you know, and you'll have a working script. Sorry about the delay.

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  15. I was getting the same result I think. Okay sounds good, hopefully they could clear it up.

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  16. David Peralty

    Okay, I have figured it out with the help of one of our developers. You need to take the value of the $_SERVER['HTTP_REFERER']; and put it in a hidden field. Then your redirect code becomes:

    add_filter("gform_confirmation", "custom_confirmation", 10, 4);
    
    function custom_confirmation($confirmation, $form, $lead, $ajax){
    // replace with the input number of the hidden field
    $redirurl = $_POST["input_8"]
    
        if($form["id"] == "3"){
    	$confirmation = array();
    	$confirmation['redirect'] = $redirurl;
        }
        return $confirmation;
    }
    Posted 11 years ago on Friday July 13, 2012 | Permalink
  17. Okay, I think I get it-- I added a ';' after the post input line btw.

    All that returned was the word "array" printed? No redirect or anything

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  18. David Peralty

    Sorry, forgot the semicolon. $redirurl = $_POST["input_8"];

    You will have to edit it via FTP or whatnot... because WordPress doesn't handle syntax errors well.

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  19. All that was outputted was the word 'array' printed in place of the form...

    I put $_SERVER['HTTP_REFERER']; (also tried $_SERVER['HTTP_REFERER']) as a default value in a single line text box that was hidden..

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  20. David Peralty

    Your code to add the value to the hidden field should look something like the following:

    add_filter("gform_pre_render_3", "redirecturl");
    add_filter("gform_admin_pre_render_3", "redirecturl");
    
    function redirecturl($form){
     foreach($form["fields"] as &$field){
    	if($field["id"] == 8){
    		$field["defaultValue"] = $_SERVER['HTTP_REFERER'];
    	}
     }
     return $form;
    }
    Posted 11 years ago on Friday July 13, 2012 | Permalink
  21. I am still getting the same result with the word 'array' printed. I posted my exact code from my functions.php file here: http://pastebin.com/v4wR10AE

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  22. David Peralty

    Can you e-mail me an admin login... we are so close that I would like to tweak it and test it as I go to try to get this solved for you today.

    My e-mail is peralty@rocketgenius.com

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  23. SOLUTION: Below is the solution to this problem. If you would like an automatic redirect to the previous page, here is the code to help you out. A very special thanks to David Peralty for this solution.

    Insert this code into your functions.php file

    add_filter("gform_confirmation", "custom_confirmation", 10, 4);
    
    function custom_confirmation($confirmation, $form, $lead, $ajax){
    // replace with the input number of the hidden field
    $redirurl = $_POST["input_2"];
    
        if($form["id"] == "1"){
    	$confirmation = array();
    	$confirmation['redirect'] = $redirurl;
        }
        return $confirmation;
    }
    
    add_filter("gform_pre_render_1", "redirecturl");
    add_filter("gform_admin_pre_render_1", "redirecturl");
    
    function redirecturl($form){
     foreach($form["fields"] as &$field){
    	if($field["id"] == 2){
    		$field["defaultValue"] = $_SERVER['HTTP_REFERER'];
    	}
     }
     return $form;
    }

    Three important points:
    --Where you see the number 1 is where you will need to fill in the form ID for the form you wish to apply the redirect
    --Add a blank text box to your form, the ID of this box is the number you insert where you see the number 2. This text box is where the form will store your redirect url for after submission
    --It is important to A) set that field to be dynamically populated (leave it blank though) and to B) hide it using CSS (add a class to form then add a line like .formclass {display: none;} to your css stylesheet)-DO NOT set it to be visible by admin only, it will not work if you do that.

    This works great for combining the User Registration add-on and setting forms to "user must be logged in"--place a link to a user registration form in the error message with this enabled and users will be redirected right back to the form after registering (there is also code on this forum for auto-login that really completes the process).

    Posted 11 years ago on Friday July 13, 2012 | Permalink
  24. David Peralty

    Thanks for taking the time to post this. :)

    Posted 11 years ago on Friday July 13, 2012 | Permalink