gform_addon_field_value

gform_addon_field_value

DescriptionUsageParametersExamples1. Change Value of Specific Field2. Use Choice Text Instead of ValuePlacementSource CodeSince

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

$field_value string
The value to be modified.

$form Form Object
The form currently being processed.

$entry Entry Object
The entry currently being processed.

$field_id string
The id of the field currently being processed.

$slug string
The add-on slug, including the gravityforms prefix. See the Gravity Forms Add-On Slugs article for a list of possible slugs.

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 should be placed in the functions.php file of your active theme.
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.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注