gravityflow_step_is_condition_met

The gravityflow_step_is_condition_met filter allows customization of whether a step should be executed or not.  It executes for every step, and would occur after any potential step conditions have been evaluated.

Parameters

Parameter Type Definition
$condition_met boolean Should the step start?
$logic Array Any conditional logic defined for the step.
$form Array The form object for the current entry.
$entry Array The current entry array.
$step Gravity_Flow_Step The current step.

Examples

Example 1 - Complex Logic?

The logic via the UI is limited to ANY ( OR evaluator) or ALL ( AND evaluator).This is an example of evaluating a compound rule scenario that requires field 12 = Payment AND either field 7 OR field 9 not be blank.

add_filter( 'gravityflow_step_is_condition_met', 'sh_step_condition_met_complex_evaluation'), 10, 5);
function sh_step_condition_met_complex_evaluation( $do_action, $logic, $form, $entry, $step ) {
    if ( false == $step ) {
        return false;
    }

    //Update the Step ID you want to limit this to
    if ( $step->get_id() != 105 ) {
        return false;
    }

    //Update the field IDs and logic for your scenario
    if ( ( empty( $entry['7'] ) || empty( $entry['9'] ) ) && $entry['12'] == 'Payment' ) {
        $do_action = true;
    } else {
        $do_action = false;
    }
    return $do_action;
}

Example 2 - Checking for other entries

This scenario demonstrates using the Gravity Forms API to check another form for comparative values.
It uses the value of a field in current entry (field ID 7), to compare if any other entries exist based on matching to form 14, field ID 1.

add_filter( 'gravityflow_step_is_condition_met', 'sh_step_condition_met_matching_separate_entry_check', 10, 5);
function sh_step_condition_met_matching_separate_entry_check( $do_action, $logic, $form, $entry, $step ) {
    if ( false == $step ) {
        return false;
    }

    $step_id = $step->get_id();
    //Update the list of step IDs you want this to execute against
    if ( false == in_array( $step_id, array( '109', '111' ) ) ) {
        return false;
    }
    //Update the field IDs and form ID you want this to compare against
    if( !empty( $entry['7'] ) ) {
        $search_criteria['field_filters'][] = array( 'key' => '1', 'value' => $entry['7'] );
        $paging      = array( 'offset' => 0, 'page_size' => 1 );
        $total_count = 0;
        $apps        = GFAPI::get_entries( 14, $search_criteria, array(), $paging, $total_count );
        if( ! empty( $apps ) ) {
            $do_action = true;
        } else {
            $do_action = false;
        }
    } else {
        $do_action = false;
    }
    return $do_action;
}

Example 3 - Checking that a subscriber role type was chosen in Assignee field

The Assignee field type cannot currently be used in the UI for conditional logic for steps. This example would only execute the step if Subscriber role type was chosen.

add_filter( 'gravityflow_step_is_condition_met', 'sh_step_condition_met_complex_evaluation', 10, 5);
function sh_step_condition_met_complex_evaluation( $do_action, $logic, $form, $entry, $step ) {
    if ( false == $step ) {
        return $do_action;
    }

    //Update the Step ID you want to limit this to
    if ( $step->get_id() != 202 ) {
        return $do_action;
    }

    //Update the field IDs and logic for your scenario
    $assignee_field = explode( '|', $entry['1'] );

    if ( isset( $assignee_field[1] ) && $assignee_field[1] == 'subscriber' ) {
        $do_action = true;
    } else {
        $do_action = false;
    }
    return $do_action;
}

Example 4 - Checking file type of all upload fields

The Assignee field type cannot currently be used in the UI for conditional logic for steps. This example would only execute the step if Subscriber role type was chosen.

add_filter( 'gravityflow_step_is_condition_met', 'jo_step_condition_upload_file_type', 10, 5);
function jo_step_condition_upload_file_type( $do_action, $logic, $form, $entry, $step ) {
	if ( false == $step ) {
		return $do_action;
	}
	//Update the Step ID you want to limit this to
	if ( $step->get_id() != 548 ) {
		return $do_action;
	}

	foreach ( $form['fields'] as $field ) {
		//Ensure this is only evaluating upload fields
		if ( ! $field instanceof GF_Field_FileUpload ) {
			continue;
		}

		//If you want to check a subset of upload fields - evaluate the $field['id'] is in_array before the rest of the logic within the loop.
		if ( isset( $entry[ $field['id'] ] ) ) {
			//Update the list of file types you want to check for.
			$allowed = array('gif', 'png', 'jpg');
			if ( ! empty( $entry[ $field['id'] ] ) ) {
				$multiple = json_decode( $entry[ $field['id'] ] );
				//To address upload fields with single versus multiple upload patterns.
				if ( json_last_error() === JSON_ERROR_NONE ) {
					foreach ( $multiple as $filename ) {
						$ext = pathinfo( $filename, PATHINFO_EXTENSION );
						if ( in_array( $ext, $allowed ) ) {
							$do_action = true;
						}
					}
				} else {
					//Field is a single file upload type
					$filename = $entry[ $field['id'] ];
					$ext = pathinfo( $filename, PATHINFO_EXTENSION );
					if ( in_array( $ext, $allowed ) ) {
						$do_action = true;
					}
				}
			}
		}
	}
	return $do_action;
}

Placement

This code should be placed in the functions.php file of your active theme or in a custom functions plugin.