Description
This filter can be used to modify a value before it is sent to a third-party by one of the Add-On Framework based add-ons. If you want to filter the value for a specific add-on you can use gform_short_slug_field_value.
Usage
The base filter which would run for all forms and all fields would be used like so:
add_filter( 'gform_addon_field_value', 'your_function_name', 10, 5 )
To target a specific form append the form id to the hook name. (format: gform_addon_field_value_FORMID)
add_filter( 'gform_addon_field_value_10', 'your_function_name', 10, 5 );
To target a specific field append both the form id and the field id to the hook name. (format: gform_addon_field_value_FORMID_FIELDID)
add_filter( 'gform_addon_field_value_10_3', 'your_function_name', 10, 5 );
Parameters
Parameter | Type | Description |
---|---|---|
$field_value | mixed | The current value of the field before being filtered. |
$form | Form Object | The form currently being processed. |
$entry | Entry Object | The entry currently being processed. |
$field_id | string | The ID of the field being processed. |
$slug | string | The add-on slug, used to namespace the filter hook. |
Examples
1. Change Value of Specific Field
This example shows how you can change the value of field 3 on form 10 before it is passed to any of the feed add-ons.
add_filter( 'gform_addon_field_value_10_3', function ( $field_value, $form, $entry, $field_id ) {
return 'your new value';
}, 10, 4 );
2. Use Choice Text Instead of Value
This example shows how you can replace the value of a choice based survey field with the choice text.
add_filter( 'gform_addon_field_value', 'gf_get_choice_text', 10, 5 );
function gf_get_choice_text( $field_value, $form, $entry, $field_id, $slug ) {
$field = RGFormsModel::get_field( $form, $field_id );
if ( is_object( $field ) && $field->type == 'survey' ) {
$field_value = $field->get_value_export( $entry, $field_id, true );
}
return $field_value;
}
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?
Source Code
$field_value = gf_apply_filters( array( 'gform_addon_field_value', $form['id'], $field_id ), $field_value, $form, $entry, $field_id, $this->_slug );
This filter is located in GFAddOn::get_field_value() in includes/addon/class-gf-addon.php.
Since
This filter was added in Gravity Forms 1.9.15.12.