gravityflow_step_complete

The gravityflow_step_complete action fires on the completion of a step.

Examples

Example 1 -  At the conclusion of a step write the value from a text field into the timeline and blank out the field value.

add_action( 'gravityflow_step_complete', 'sh_gravityflow_step_complete', 10, 4 );
function sh_gravityflow_step_complete( $step_id, $entry_id, $form_id, $status ) {
    if ( $step_id == '5' ) {
        $entry = GFAPI::get_entry( $entry_id );
        if ( ! is_wp_error( $entry ) && isset( $entry['1'] ) && ! empty( $entry['1'] ) ) {
            gravity_flow()->add_timeline_note( $entry_id, 'Message from customer: ' . $entry['1'] );
            GFAPI::update_entry_field( $entry_id, '1', '' );
        }
    }
}

Example 2 - Updating User Field from Email Field

Update a hidden user field on a form based on a visible email field. This might be invoked on the conclusion of an Approval Step

add_action( 'gravityflow_step_complete', 'sh_gravityflow_step_complete', 10, 4 );
function sh_gravityflow_step_complete( $step_id, $entry_id, $form_id, $status ) {
	//Field 2 = Email
	//Field 3 = User Field
	// ensure correct step id
	if ( $step_id == '192' ) {
        	// get the entry details
        	$entry = GFAPI::get_entry( $entry_id );
        	// get user by email input
        	$user = get_user_by( 'email', $entry[2] );
        	// update the user ID in the hidden user field if it matches
		if ( ! $user ) {
	        	GFAPI::update_entry_field( $entry_id, '3', $user->ID );
		}
}
}

Placement

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