Creating Conditional Redirects or Conditional Confirmation Messages with Gravity Forms.

UPDATE: This post is really old, if you’re looking at this now you should ignore it. Gravity Forms has a much better way of doing this with “conditionals” in the native settings. Do that!

One of the features Gravity Forms plans to offer in the future is redirecting to specific pages based on field submissions. While they currently support a full page redirect–meaning once you submit the form rather than getting a “Thanks!” message you are taken to a specific URL–they don’t currently offer a system to redirect to a specific page based on the selection of a specific field. After working on a project for someone I stumped on a method that will allow you to do this by simply creating an additional PHP file.

To create this system the first thing you’ll want to do is create a new form as you typically would. In this example I will be using a question about comparing the band “Green Day” to “Blink 182”.

You can see the final product of this setup here

The first thing you’ll want to do is create a php file with the following code:

As you can see in this example I created a system to define a specify page for each option using this pattern:

case “OPTION“:
header(“Location: URLTOREDIRECT“);

You’d repeat this for each option you plan on creating in your form, however, for my example we are just using two items. Once I created this php file I named it redirect.php and uploaded it to the root of my web directory.

Now that the PHP system to redirect is in place you’ll want to go into Gravity Forms and create a form that corresponds with the items you setup in the php file as shown below:

Once you’ve got the field options set you’ll want to go to the Form Settings and then select Confirmation

You’ll then want to set the Confirmation Message to Redirect and then paste the URL to your php file as the URL. Once that’s set you’ll want to check the option that reads Pass field Data via Query String

Once this option is checked you’ll want to type agree= into the input box below. Then use the Insert Merge Tag dropdown to select the field you created for the redirects. In this instance it was the What band would you prefer? field. Once you select the field you plan on using it should insert the appropriate text automatically–as shown below:

Once this is set you should Update/Save the form you created and then proceed to view it. You’ll find that depending on the option selected when you submit the form the user will be redirected to the URL you defined in your PHP file!

Easy as pie!