gform_get_input_value

Description

The gform_get_input_value filter allows developers to change the field’s value after being retrieved from the database. Use in conjunction with gform_save_field_value to perform low-level transformations, such as encrypting/decrypting a field.

Usage

The base filter which would run for all forms and all fields would be used like so:

add_filter( 'gform_get_input_value', 'your_function_name', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_get_input_value_FORMID)

add_filter( 'gform_get_input_value_10', 'your_function_name', 10, 4 );

To target a specific field append both the form id and the field id to the hook name. (format: gform_get_input_value_FORMID_FIELDID)

add_filter( 'gform_get_input_value_10_3', 'your_function_name', 10, 4 );

Parameters

ParameterTypeDescription
$valuestringField value to be filtered.
$entryEntry ObjectCurrent entry object.
$fieldField ObjectCurrent Field object.
$input_idfloatFor multi-input fields (i.e. name, address, checkboxes), this parameter will hold the input ID. For single input fields, this parameter will be blank.

Examples

Decode all values.

This example assumes the field values were base 64 encoded, and decodes them so that they can be properly displayed. View gform_save_field_value for an example on how to encode the fields.

add_filter( 'gform_get_input_value', 'decode_field', 10, 4 );
function decrypt_field( $value, $entry, $field, $input_id ) {
	return base64_decode( $value );
}

This example uses the GFCommon::decrypt() method.

add_filter( 'gform_get_input_value', 'decode_field', 10, 4 );
function decrypt_field( $value, $entry, $field, $input_id ) {
	return GFCommon::decrypt( $value );
}

Decode values for a specific form.

This is another example where you may select a specific form and specific fields to decode. It is also assumed that the values were base 64 encoded.

<pre class="wp-block-syntaxhighlighter-code">add_filter( 'gform_get_input_value', 'decode_field', 10, 4 );
function decode_field( $value, $entry, $field, $input_id ) {
	//if not the form with fields to decode, just return the unaltered value without checking the fields
	if ( absint( $entry['form_id'] ) <> 94 )
		return $value;
	//array of field ids to decode
	$decode_fields = array( 1,2,3 );
	//see if the current field id is in the array of fields to decode; decode if so, otherwise return unaltered value
	if ( in_array( $field->id, $decode_fields ) ) {
		return base64_decode( $value );
	} else {
		return $value;
	}
}</pre>

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

This filter is located in the following methods in forms_model.php:

  • GFFormsModel::get_field_value_long()
  • GFFormsModel::build_lead_array()

Since

The base filter was added in Gravity Forms 1.5.2.1. The form and field specific versions were added in Gravity Forms 1.9.13.6.