Is it possible to have different thank you pages based on a drop down field in the form?
Is it possible to have different thank you pages based on a drop down field in the form?
Continued from here:
http://www.gravityhelp.com/forums/topic/custom-thank-you-pages-based-on-drop-down-field
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
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.
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;
}
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;
}
Havent heard back, I went ahead and tried with a fresh copy of wordpress with 2011 theme. Still doesn't work.
Please respond.
@Brian, please change all references of $entry['1'] to $lead['1']. There was a mistake in my earlier code.