Question

I want to redirect based on conditions in Gravity Forms.

//REDIRECT BASED ON GRAVITY SELECTIONS
add_filter( 'gform_confirmation_17', __NAMESPACE__ . '\\redirectfilter', 10, 4 );
function redirectfilter($confirmation, $form, $entry, $ajax) {
    GFCommon::log_debug( __METHOD__ . '(): started.' );
    session_start();

    $laatste = $entry['1'];

    if(isset($_SESSION['form'])) {
        GFCommon::log_debug( __METHOD__ . '(): SESSION[form] is set.' );
        $result = array();

        foreach($_SESSION['form'] as $row){
            $result[] = $row;
        }

        if ($result[0] === 'Diesel' &&  $result[1] === 'Mobiel' && $laatste === 'Kunststof'  ) {

            GFCommon::log_debug( __METHOD__ . '(): Diesel and Mobiel and Kunststof' );

            $confirmation = array('redirect' => esc_url(home_url('/producten/filters/brandstof/diesel/materiaal/kunststof/toepassing-filter/mobiel/')));
        } else {
            $confirmation = "Geen producten gevonden aan jouw criteria";
        }   

    }

    GFCommon::log_debug( __METHOD__ . '(): finished.' );
    return $confirmation;       
}

But I cant seem to get it to work, I have the feeling i'm missing something but I can't find it :/

You can find my Gravity Forms log here: http://pastebin.com/hm5RYpyZ.

Help will be greatly appreciated.

Best Regards,

Dylan Smit

Was it helpful?

Solution

I think there is no need for this approach. You should try this:

  1. Go to Form editor / Confirmations
  2. Create confirmation
  3. At the bottom of the screen you can find Conditional Logic, from there you can select specific field values.
  4. Set Confirmation Type as Redirect

Repeat process for all Confirmation options / redirects you need to offer.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top