Description
Use this filter to change the field’s value before getting displayed on the Entry detail page. Useful when creating custom field types that require special formatting when displayed,
Usage
add_filter( 'gform_entry_field_value', 'category_names', 10, 4 );
Parameters
- $value string
The current entry value to be filtered.
-
$field Field Object
The field from which the entry value was submitted.
-
$entry Entry Object
The current entry.
-
$form Form Object
The form from which the entry value was submitted.
Examples
1. Display category name
This example assumes the original value is a comma delimited list of category IDs (i.e. ‘1,3,4’). We then break the IDs into an array, loop through each ID to get the category name, and format the category name into an unordered list.
add_filter( 'gform_entry_field_value', 'category_names', 10, 4 ); function category_names( $value, $field, $lead, $form ) { if ( $form['id'] != 104 || $field->id != 3 ) return $value; $newvalue = *; $categories = explode( ',', $value ); foreach ( $categories as $category ) { $new_value .= '<li>' . get_cat_name( $category ) . '</li>'; } return '<ul>' . $new_value . '</ul>'; }
2. Display choice label
This example displays the choice label instead of value for choice based fields.
add_filter( 'gform_entry_field_value', function ( $value, $field, $entry, $form ) { $classes = array( 'GF_Field_Checkbox', 'GF_Field_MultiSelect', 'GF_Field_Radio', 'GF_Field_Select', ); foreach ( $classes as $class ) { if ( $field instanceof $class ) { $value = $field->get_value_entry_detail( RGFormsModel::get_lead_field_value( $entry, $field ), $currency = '', $use_text = true, $format = 'html' ); break; } } return $value; }, 10, 4 );
3. File Uploads
This example shows how you could display uploaded images in a Multi-File upload field.
add_filter( 'gform_entry_field_value', function ( $value, $field, $entry, $form ) { if ( $field->get_input_type() == 'fileupload' && $field->multipleFiles && ! empty( $value ) ) { // Multi-File upload field $value = ''; $raw_value = rgar( $entry, $field->id ); $files = empty( $raw_value ) ? array() : json_decode( $raw_value, true ); foreach ( $files as $file_url ) { $value .= sprintf( "<a href='%s' target='_blank' title='%s'><img src='%s' width='100' /></a><br>", $file_url, __( 'Click to view', 'gravityforms' ), $file_url ); } } return $value; }, 10, 4 );
And the following does the same for a single file upload field.
add_filter( 'gform_entry_field_value', function ( $value, $field, $entry, $form ) { if ( $field->get_input_type() == 'fileupload' && ! empty( $value ) ) { // Single file upload field $file_url = rgar( $entry, $field->id ); $value = sprintf( "<a href='%s' target='_blank' title='%s'><img src='%s' width='100' /></a><br>", $file_url, __( 'Click to view', 'gravityforms' ), $file_url ); } return $value; }, 10, 4 );
Additional Notes
This hook is useful for storing entry values in one format, while displaying them on the entries page in another (refer to the example above).
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFEntryDetail::lead_detail_grid() in entry_detail.php.