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? Default = true
$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 to ensure your customized logic applies on your expected step.
    if ( $step->get_id() != 105 ) {
        return $do_action;
    }

    //Update the field IDs and logic for your scenario. This example will ensure the step runs if either (Field 7 OR Field 9 is NOT blank) AND Field 12 is equal to Payment
    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.
The step will only be performed if there are entries in form 14.

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 $do_action;
    }<br>
    //Update the field IDs and form ID you want this to compare against<br>   //This example 
    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 false;
    }

    //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;
}

Example 5 - Multiple steps using same filter to checking different form fields for a common value

This is similar to Example 2 above, but uses multiple step IDs to compare different form/field values. It can be a very flexible approach to, for example, use just two Form Connector Update an Entry steps along with Example 2 of the gravityflowformconnector_update_entry_id to create a conditionally repeating loop to update as many entries which have a matching field/value.

add_filter( 'gravityflow_step_is_condition_met', 'jo_step_condition_multiple_field_match_entry_check', 10, 5);
function jo_step_condition_multiple_field_match_entry_check( $do_action, $logic, $form, $entry, $step ) {

	if ( false == $step ) {
		return false;
	}

	// Ensure this filter only applies for the desired form.
	if ( $form['id'] != '15' ) {
		return $do_action;
	}

	$step_id = $step->get_id();

	// Update the list of step IDs you want this to execute against.
	if ( false == in_array( $step_id, array( '65', '66', '68', '69', '70', '71' ) ) ) {
		return $do_action;
	}
		$original_value = $entry['1'];

	// Based on the Step, define what search form and criteria are to be used.
	switch ( $step_id ) :
		case 65:
		case 66:
			$search_form_id = '17';
			$search_criteria['field_filters'][] = array( 'key' => '3', 'value' => $original_value );
			break;

		case 68:
		case 69:
			$search_form_id = '18';
			$search_criteria['field_filters'][] = array( 'key' => '2', 'value' => $original_value );
			break;

		case 70:
		case 71:
			$search_form_id = '16';
			$search_criteria['field_filters'][] = array( 'key' => '1', 'value' => $original_value );
			break;

	endswitch;

	$paging         = array( 'offset' => 0, 'page_size' => 1 );
	$total_count    = 0;
	$candidates = GFAPI::get_entries( $search_form_id, $search_criteria, array(), $paging, $total_count );

	if ( ! empty( $candidates ) ) {
		$do_action = true;
	} else {
		$do_action = false;
	}

	return $do_action;
}

Placement

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