The gform_get_field_value filter in Gravity Forms allows you to modify the value of a field for a specific entry.
Usage
add_filter('gform_get_field_value', 'your_function_name', 10, 3);
Parameters
$value
(string) – The current value of the field.$entry
(Entry Object) – The current entry.$field
(Field Object) – The current field.
More information
See Gravity Forms Docs: gform_get_field_value
Examples
Change the value of a specific field
In this example, we change the value of field ID 1 to “Testing”.
add_filter('gform_get_field_value', 'change_field_value', 10, 3); function change_field_value($value, $entry, $field) { if ($field['id'] == 1) { $value = 'Testing'; } return $value; }
Uppercase the value of a specific field
In this example, we change the value of field ID 2 to uppercase.
add_filter('gform_get_field_value', 'uppercase_field_value', 10, 3); function uppercase_field_value($value, $entry, $field) { if ($field['id'] == 2) { $value = strtoupper($value); } return $value; }
Reverse the value of a specific field
In this example, we reverse the value of field ID 3.
add_filter('gform_get_field_value', 'reverse_field_value', 10, 3); function reverse_field_value($value, $entry, $field) { if ($field['id'] == 3) { $value = strrev($value); } return $value; }
Add a prefix to the value of a specific field
In this example, we add a prefix “GF-” to the value of field ID 4.
add_filter('gform_get_field_value', 'prefix_field_value', 10, 3); function prefix_field_value($value, $entry, $field) { if ($field['id'] == 4) { $value = 'GF-' . $value; } return $value; }
Format the value of a specific field as a currency
In this example, we format the value of field ID 5 as a currency with two decimal places and a dollar sign.
add_filter('gform_get_field_value', 'format_currency_field_value', 10, 3); function format_currency_field_value($value, $entry, $field) { if ($field['id'] == 5) { $value = '$' . number_format((float)$value, 2, '.', ','); } return $value; }