Using Gravity Forms ‘gform_get_input_value’ PHP filter

The gform_get_input_value filter allows you to modify a field’s value after it has been retrieved from the database. It can be used in combination with gform_save_field_value to perform low-level transformations, such as encrypting/decrypting a field.

Usage

To use the base filter for all forms and all fields:

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): The field value to be filtered.
  • $entry (Entry Object): The current entry object.
  • $field (Field Object): The current field object.
  • $input_id (float): For multi-input fields (e.g. name, address, checkboxes), this parameter holds the input ID. For single input fields, this parameter will be blank.

More information

See Gravity Forms Docs: gform_get_input_value

Examples

Decode all values

This example assumes the field values were base64 encoded and decodes them so they can be properly displayed.

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

function decrypt_field($value, $entry, $field, $input_id) {
    return base64_decode($value);
}

Decode values for a specific form

In this example, you can select a specific form and specific fields to decode. It is also assumed that the values were base64 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.