gform_form_pre_process_async_task

Description

The gform_form_pre_process_async_task filter can be used to modify the form object before notifications and add-on feeds are processed by the async (background) task processor.

Usage

The filter which runs for all forms would be used like so:

add_filter( 'gform_form_pre_process_async_task', 'your_function_name', 10, 2 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_form_pre_process_async_task_FORMID)

add_filter( 'gform_form_pre_process_async_task_5', 'your_function_name', 10, 2 );

Parameters

Examples

Add choice based on entry value

This example shows how you can add a choice to a field object if the entry for another field contains a specific value.

add_filter( 'gform_form_pre_process_async_task', function ( $form, $entry ) {
	if ( rgar( $entry, '1' ) === 'test' ) {
		$field = GFAPI::get_field( $form, 2 );
		if ( $field && is_array( $field->choices ) ) {
			$field->choices[] = array( 'text' => 'Testing', 'value' => 'test' );
		}

	}

	return $form;
}, 10, 2 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in Gravity Forms v2.6.9.

Source Code

This filter is located in GF_Background_Process::filter_form() in /includes/libraries/gf-background-process.php.