Description
Use this filter 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
- $value string
Field value to be filtered.
-
$entry Entry Object
Current entry object.
-
$field Field Object
Current Field object.
-
$input_id float
For 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
1. 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 ); }
2. 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.
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; } }
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_apply_filters( 'gform_get_input_value', array( $field->formId, $field->id ), $val, $lead, $field, $input_id )
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