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.

Terms of Conditions

  1. I'm making a form for Terms of conditions so I need when yes is checked the user to be transferred to one page and if the check no, for them to be redirected to a different page.
    Thoughts?

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  2. You can pass a query string parameter to the confirmation page (agree or disagree) and use a php switch statement to redirect from there based on the value.

    Somebody had a similar request a while before and there's more info on this thread

    http://forum.gravityhelp.com/topic/add-conditional-logic-to-submit-button

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  3. Hey Kevin, I'm kind of code stupid... so wondering if you can kind of walk me through this. On the Pass Field Data Via Query String did you add purchase= and why. When you talk about adding a switch on the confirmation page, is that the page that the form is on?

    Also are the case online, and case in-store the choices you have to choose from in your form. Hope that makes sense. Thanks

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  4. Well, that example was really tailored towards that situation, but the concept is the same. I'll take a few minutes and try to put something else together that makes a bit more sense for you. I'll post it back here a little later.

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  5. That would be great, thanks Kevin.

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  6. promedia
    Member

    Hi Kevin, are you going to make this tutorial public? I would love to see this tutorial, code doesn't really make sense to me...

    Thanks

    ~ Vincent

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  7. Okay, here goes.

    You'll want to create your form and go to the redirection tab, or update the redirection settings on your current form. I would suggest redirecting back to the same page the form actually resides on (we will add a little PHP on that page in another step) and pass a query string parameter. In my example, I called the parameter "agree" to keep it simple. You'll want to type in "agree=" then choose the actual form field from your drop down list so it adds the correct one to your string. It will be in the format of {field label:#}.

    Here's the example screenshot

    Once that's done, you'll need to create a new page template and add some php to handle the redirection. You can copy your normal page.php file save it as a different file name and add the following at the very top of the file.

    <?php
    /*
    Template Name: form terms redirect
    */
    ?>
    
    <?php
    // redirect form based on the agree/disagree value passed in querystring
    $agree = $_GET['agree'];
    
    	switch ($agree)
    	{
    
    		case yes:
    		// if yes redirect to the following page
    		header("Location: http://www.yourdomain.com/agree_to_terms_page_name/");
    		break;
    
    		case no:
    		// if no redirect to the following page
    		header("Location: http://www.yourdomain.com/disagree_to_terms_page_name/");
    		break;
    
    	}
    ?>

    You can modify the template name to your preference and you'll need to modify the URLs in the switch statement to point to the appropriate pages on your site.

    You can see my example page template here

    Once you've created the page template and have uploaded it to your theme. You'll need to go to the page admin, select the page the form is currently on, and switch the template to the new one you just created. You'll see the option in the right sidebar on the page admin.

    example screenshot

    Once you've done that, you should be good to go. In a nutshell, here's what's happening. We're redirecting the form back to the same page but passing a variable either "agree=yes" or "agree=no" in the URL. The PHP detects this and automatically redirects to the appropriate page based on the value it sees.

    I hope that helps get you on your way a little better.

    Posted 12 years ago on Monday December 7, 2009 | Permalink
  8. With such good explanation, you would figure I would be able to not screw anything up. But well I hit submit on my form it actually reconfigures the whole page, changes what text was on it and everything.
    When I hit no I get this http://www.blendswap.com/submit-blend/?agree=No%2C+Way
    When I hit yes I get this: http://www.blendswap.com/submit-blend/?agree=Agree

    Really not sure what I'm doing wrong.
    Any thoughts, Kevin.

    Posted 12 years ago on Tuesday December 8, 2009 | Permalink
  9. Is it possible to just pay you guys to set all of this up for me? Would probably save me a ton of time and headache.

    Posted 12 years ago on Tuesday December 8, 2009 | Permalink
  10. if you can send me a login to your site, I can take a couple of minutes and look it over. Send to kevin at rocketgenius.com

    Posted 12 years ago on Tuesday December 8, 2009 | Permalink
  11. Sent your way. Thanks man.

    Posted 12 years ago on Tuesday December 8, 2009 | Permalink
  12. promedia
    Member

    Unbelievable... I got it to work after almost 3 hours (and I'm not joking).

    It's indeed an excellent explanation and it seemed all very logical but I was already stuck at the redirection tab.... I just spent at least an hour searching the redirection tab and I found it via a post here on the forum. "(1) In the form editor screen, go to the "Form Settings" (top right of screen)" hmmm :(

    But, I got it to work and it looks like it works correctly. I have to do some additional testing but I believe it works okay.

    Thanks a lot Kevin, you rock!! I really appreciate your vivid explanation! Thank you!

    Posted 12 years ago on Tuesday December 15, 2009 | Permalink
  13. David
    Member

    This code above looks good. The instructions are great. I'm close to getting it to work, but the addition of the php switch to a new page template causes havok on my layout.

    It looks fine with my existing page template
    http://www.myfoursquare.net/test

    But looks nasty with the php switch page template
    http://www.myfoursquare.net/test-with-template

    Either way, I am still not getting the redirect working. Anyone have any suggestions for this? Thanks!

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  14. David
    Member

    OK. So I sorted out the nasty formatting. My mistake.

    What I had done was to copy all of Kevin's "example page template" from the link above.

    What I should have done, was to copy only the top section of his example (excluding all of the code he had from <?php get_header(); ?> onwards). I basically had two chunks of the normal page template repeated...

    Cool!

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  15. David
    Member

    Still getting this error though:

    Warning: Cannot modify header information - headers already sent by (output started at /home2/myfoursq/public_html/wp-content/themes/coffeebreak/template-gravityredirect.php:7) in /home2/myfoursq/public_html/wp-content/themes/coffeebreak/template-gravityredirect.php on line 21

    Depending on which value I choose in the dropdown (yes or no), I get the error above with the php row number corresponding to the location line for yes (16) or for no (21).

    I'm using this code in my template:

    <?php
    /*
    Template Name: Gravity Redirect
    */
    ?>
    
    <?php
    // redirect form based on the agree/disagree value passed in querystring
    $agree = $_GET['agree'];
    
    	switch ($agree)
    	{
    
    		case yes:
    		// if yes redirect to the blog
    		header("Location: http://www.myfoursquare.net/archives");
    		break;
    
    		case no:
    		// if no redirect to the contact page
    		header("Location: http://www.myfoursquare.net/contact-new");
    		break;
    
    	}
    ?>

    Any ideas?

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  16. Okay, looking back at this now, not sure what I was smoking, but this wasn't really clear enough. Here's the full run down, and hopefully a little easier to follow.

    You'll want to create a totally new file for the page template.. I called mine template_redirect.php in the root of the theme directory. Open that file, and add this..

    <?php
    // redirect form based on the agree/disagree value passed in querystring
    $agree = $_GET['agree'];
    
    	switch ($agree)
    	{
    
    		case "yes":
    		// if yes redirect to the following page
    		header("Location: http://www.yourdomain.com/agree_to_terms_page_name/");
    		break;
    
    		case "no":
    		// if no redirect to the following page
    		header("Location: http://www.yourdomain.com/disagree_to_terms_page_name/");
    		break;
    
    	}
    
    /*
    Template Name: form terms redirect
    */
    
    ?>

    Since we're using this simply for a redirect, we don't need anything else on the page. Of course, you'll configure the URL's to your actual destination pages.

    Next, you'll want to go to "add pages", create a new page then select the "form terms redirect" as the page template. Name the page "redirect" then save everything.

    page settings

    Next, go to your form, click on the form settings at the top of the page, then the confirmation tab. Select the "redirect" option under the confirmation message heading. There you will put in the URL of the page you want to redirect the form to.. in this case, to the page you just created so something like.. "http://www.yourdomain.com/redirect/"

    Then, you'll need to check the "Pass Field Data Via Query String" option and build your query string. You have to manually add the first portion "agree=" then select from the drop down list directly above that field and find the "agree" field in your form, click on that and it will insert the proper token to populate the query string.

    confirmation settings example

    Save the form settings, then go test your form. The form should redirect to the confirmation page you created, then based on the agree field value passed to it, will redirect to whatever page you want from there.

    I hope that helps clear it up a bit.

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  17. David
    Member

    Kevin, thanks for this great step-by-step. I must have been smoking some of that as well, as I've done all of the above, and I still haven't got it working.

    The clean template you provided above fixes the header errors so that is great. However, I still can't get the redirect happening. I do get to see http://www.myfoursquare.net/redirect?agree=yes and http://www.myfoursquare.net/redirect?agree=no in the address bar, but these don't then connect to the pages set in the php template file.

    Can I just check one thing. The form: Are we talking checkboxes or drop down? Does it matter? I have tried both. I am currently using a dropdown with Field Label "Agree to Terms?" and two Choices: "yes" and "no"

    My page with the form:
    http://www.myfoursquare.net/page-with-form

    My query string (which I built using the form field drop down):
    agree={Agree to terms?:1}

    My redirect page:
    http://www.myfoursquare.net/redirect

    My Template code:

    <?php
    // redirect form based on the agree/disagree value passed in querystring
    $agree = $_GET['Agree'];
    
    	switch ($agree)
    	{
    
    		case "yes":
    		// if yes redirect to the following page
    		header("Location: http://www.myfoursquare.net/archives");
    		break;
    
    		case "no":
    		// if no redirect to the following page
    		header("Location: http://www.myfoursquare.net/contact-new");
    		break;
    
    	}
    
    /*
    Template Name: form terms redirect
    */
    
    ?>
    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  18. David
    Member

    Screenshot of my form:
    http://screencast.com/t/NzdlZjlhYzI

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  19. I used a drop down like yours on my test form and it worked fine. I think something's just not configured properly somewhere still.

    Can you send an admin login to your site so I can take a look? If so, please send it via our contact form and I'll take a look. Please put "ATTN: Kevin" in your message please.

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  20. Okay, I know what it is now, it's a case issue.

    go back to your page template and change..

    $agree = $_GET['Agree'];

    to

    $agree = $_GET['agree'];

    That should get you running. It's case-sensitive and that was making it angry. Let me know if that works for you.

    Posted 12 years ago on Thursday July 15, 2010 | Permalink
  21. David
    Member

    Booyah!

    Ok. That worked great. You were right about the case issue. Kevin, this has been amazing support.
    Thankyou.

    Posted 12 years ago on Friday July 16, 2010 | Permalink
  22. David, it's totally my pleasure. I'm really pleased it worked for you. Thanks for hanging in there with me.

    Posted 12 years ago on Friday July 16, 2010 | Permalink
  23. One other note on this.. when you use the redirect page, there is sometimes a slight delay where you see the original page loading again before the redirect.

    One of our really awesome (and quite attractive) forum members came up with a quick solution using a built in filter. You can add this to your functions.php file and it simply hides the "flash" of body content until the redirect happens.

    add_filter("gform_post_submission", "hide_form", 10, 2);
    function hide_form($entry, $form) {
        if($form["confirmation"]["type"] != "message")
            echo "
    <style type=\"text/css\"> body { display: none; } </style>
    
    ";
    }

    For a full run down on what it's doing, check out Davids page via the link below.

    http://ounceoftalent.com/2010/05/gravity-forms-tip-clean-confirmation-redirects/

    Posted 12 years ago on Friday July 16, 2010 | Permalink
  24. works great with PayPal. That's what I needed. Now I need to figure out how to add amounts from text fields and radio buttons...

    Posted 12 years ago on Wednesday August 11, 2010 | Permalink

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