Gravity Forms is a great plugin with huge functionality that I use on almost all of my websites.  It just works and if there is ever a time when you cannot get it to do something that you want you can almost always find a solution through their support forums.

Recently I was trying to find a way to redirect my users to a specific url depending on which drop down they chose.  Once they submitted the form they would then be redirected to a certain url.  I used this to create a way for users to choose a purchase item in Gravity Forms and then they would be directed to a Woocommerce page within my site to actually pay for that item.

So, how did I accomplish this?  After doing some searching around the web (http://www.gravityhelp.com/forums/topic/conditional-redirect-2#post-80796) I took the directions from several sites and came up with the following snippet that works well.

Add this to your functions.php file.


// GRAVITY FORMS REDIRECT
// THIS WILL REDIRECT THE USER TO WHATEVER URL THEY SPECIFY AFTER SUBMITTING YOUR FORM
// http://www.gravityhelp.com/forums/topic/conditional-redirect-2#post-80796
// change the 1 here to your form ID if you are not using form 1
add_filter('gform_confirmation_3', 'conditional_confirmation', 10, 4);

function conditional_confirmation($confirmation, $form, $lead, $ajax){
    // change the 1 here to your field if the unit numbers not field 1
    $url = get_bloginfo();    // set a reasonable default in case we forget a unit
    switch($lead[1]) {
        case 'Name of Drop Down 1':
            $url = "http://www.google.com";
            break;
        case 'Name of Drop Down 2':
            $url = "http://www.yahoo.com/";
            break;
    }
    $confirmation = array('redirect' => $url);
    return $confirmation;
}

The things you need to change:

  • On line 6 – Change “gform_confirmation_3” to the correct form ID number.  So all you are really changing here is the number “3” to your form number.
  • On Line 12 – Change “Name of Drop Down 1” to the EXACT name of your drop down select item.
  • On Line 13 – Change the url for “http://www.google.com” to the url you want to redirect the user.

That’s it!

This Post Has 4 Comments

  1. You have one mistake, instead of:
    =>
    Please change to =>

  2. Great snippet! Thank you so much! 🙂

    I was wondering though, how would I create a conditional redirect based on two drop down selections?
    So:

    If [select 1 = option 1] & [select 2 = option 1] then redirect to URL #1
    If [select 1 = option 2] & [select 2 = option 1] then redirect to URL #2
    If [select 1 = option 1] & [select 2 = option 2] then redirect to URL #3
    If [select 1 = option 1] & [select 2 = option 2] then redirect to URL #4

  3. Patrick, did you figure out how to do this? I am also looking for that solution…

    Thanks!
    Ssara

  4. @SSSV
    Yes Gravity Forms supports conditional confirmations out of the box. Go to the “Confirmations” page under “Form Settings”. At the top you’ll see a button to “Add New”. Click this to add a new confirmation. On the confirmation edit view at the very bottom will be a section labeled “Conditional Logic” (example). You can use this section to indicate when this confirmation should be used.

Leave a Reply

Close Menu

Get in Touch

Please fill out the form below and we will get back to you ASAP

  • This field is for validation purposes and should be left unchanged.

Skip to content