gravityflowformconnector_[type]

The gravityflowformconnector_[type] filters allows the entry to be modified before create, update, submission.

  • gravityflowformconnector_new_entry
  • gravityflowformconnector_update_entry
  • gravityflowformconnector_form_submission
  • gravityflowformconnector_update_field_values

Examples

The gravityflowformconnector_new_entry filter provides a way to modify the new entry before it is created in separate form / site.

Example 1 - Include 10% into the cost of a numeric field

add_filter( 'gravityflowformconnector_new_entry', 'sh_gravityflowconnector_adjust_new_entry', 10, 5); 
function sh_gravityflowconnector_adjust_new_entry( $new_entry, $entry, $form, $target_form, $step ) { 	
	//Adding 10% to the total cost
	$new_entry['3'] = $new_entry['3'] * 1.10;
	return $new_entry;
}

Example 2 - Ensure a field with 'No Duplicates' specified in settings is respected when attempting to create a new entry.

The New Entry step relies on the Gravity Forms API for add_entry which docs state that, "The usual hooks that are triggered while saving entries are not fired here." You would need to adjust the step ID and form/field IDs to match your scenario. The add_note will log a message into the timeline of the entry executing the FC New Entry to indicate the entry was not created as expected.

add_filter( 'gravityflowformconnector_new_entry', 'sh_gravityflowconnector_adjust_new_entry', 10, 5 );
function sh_gravityflowconnector_adjust_new_entry( $new_entry, $entry, $form, $target_form, $step ) {
    //Change Step ID (121) to match your case and update the field_filters to match your target form field ID / entry field IDs
    if ( 121 == $step->get_id() ) {
        $search_criteria = array(
            'status'        => 'active',
            'field_filters' => array(
                'mode' => 'all',
                array(
                    'key'   => '2',
                    'value' => $entry['2'],
                ),
            ),
        );

        if ( GFAPI::count_entries( $target_form['id'], $search_criteria ) > 0 ) {
            //An existing entry exists in the target form so new entry should not be created. Pass a blank array back from filter
            $step->add_note( "No entry created - duplicate value exists in Form " . $target_form['id'] . " Field 2.");
            $new_entry = array();
        }
    }
    return $new_entry;
}

Example 3 - Use the Update Fields step type and copy only the last comment from a Discussion Field into the selected entry

add_filter( 'gravityflowformconnector_update_field_values', 'sh_gravityflowconnector_copy_discussion', 10, 5 );
function sh_gravityflowconnector_copy_discussion( $new_entry, $entry, $form, $target_form, $step ) {
    //Change Step ID (125) to match your workflow and update the field id (4) source / target field IDs
    if ( 125 == $step->get_id() ) {
        $discussions = json_decode( $entry['4'], ARRAY_A );
        if ( is_array( $discussions ) ) {
            //Select the specific discussion comment(s) you want and re-encode the array into JSON notation
            $last_comment = array( end( $discussions ) );
            $new_entry['4'] = json_encode( $last_comment );
        }
    }
    return $new_entry;
}


Placement

This code should be placed in the functions.php file of your active theme.