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.

Custom Thank you page based on select field choice.

  1. brianharrington
    Member

    Is it possible to have different thank you pages based on a drop down field in the form?

    Posted 11 years ago on Thursday November 1, 2012 | Permalink
  2. You can use the gform_confirmation filter in your theme's functions.php to change the confirmation URL based on a choice in your form. Documentation: http://www.gravityhelp.com/documentation/page/Gform_confirmation

    The code you use will look something like this:

    [php]
    <?php
    // change the 2 here to your form ID or remove the _2 to apply this to all forms
    add_filter('gform_confirmation_2', 'confirmation_redirect', 10, 4);
    function confirmation_redirect($confirmation, $form, $lead, $ajax){
    
    	// this will change the redirect URL based on the answer for field 5 in your form
    	if($lead['5'] == 'turtles'){
    		$confirmation = array('redirect' =>'http://www.example.com/turtle-information/');
    	}
    	else if($lead['5'] == 'frogs'){
    		$confirmation = array('redirect' =>'http://www.example.com/for-the-love-of-frogs/');
    	}
    
    	return $confirmation;
    }

    EDITED: 1 December 2012 chrishajer

    Posted 11 years ago on Friday November 2, 2012 | Permalink
  3. That code will go in your theme's functions.php.
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F#PHP

    You will need to change the 2 on line 3 to your form ID, and we're checking the value of field 5 in your form on lines 7 and 10. You can add more if statements there, or use a php switch/case statement if you have a lot of possibilities. Change the 5 on those two lines to the ID of the field you want to check the value of.

    Posted 11 years ago on Friday November 2, 2012 | Permalink
  4. brianharrington
    Member

    This didnt work for me, though the example in the link above did.

    Here is my code. Form id of 2. There is 1 drop down field with 2 choices: "1" and "2"

    add_filter('gform_confirmation_2', 'confirmation_redirect', 10, 4);
    function confirmation_redirect($confirmation, $form, $lead, $ajax){
    
      if($entry['1'] == '1'){
        $confirmation = array('redirect' =>'http://www.1.com');
      }
      else if($entry['1'] == '2'){
        $confirmation = array('redirect' =>'http://www.2.com');
      }
    
      return $confirmation;
    }
    Posted 11 years ago on Tuesday November 6, 2012 | Permalink
  5. brianharrington
    Member

    After some more investigation, if i use the below, it will redirect to 1.com regardless of what i choose in the drop down.

    add_filter('gform_confirmation_2', 'confirmation_redirect', 10, 4);
    function confirmation_redirect($confirmation, $form, $lead, $ajax){
    
      if($entry['1'] == ''){
        $confirmation = array('redirect' =>'http://www.1.com');
      }
      else if($entry['1'] == '2'){
        $confirmation = array('redirect' =>'http://www.2.com');
      }
    
      return $confirmation;
    }
    Posted 11 years ago on Wednesday November 7, 2012 | Permalink
  6. brianharrington
    Member

    Havent heard back, I went ahead and tried with a fresh copy of wordpress with 2011 theme. Still doesn't work.

    Please respond.

    Posted 11 years ago on Friday November 9, 2012 | Permalink
  7. @Brian, please change all references of $entry['1'] to $lead['1']. There was a mistake in my earlier code.

    Posted 11 years ago on Saturday December 1, 2012 | Permalink