Description
Use this filter to change the field’s value before getting displayed on the Entry list page. Useful when creating custom field types that require special formatting for the entry list.
Usage
add_filter( 'gform_entries_field_value', 'modify_entry_values' );
Parameters
- $value string
The current entry value to be filtered.
-
$form_id integer
The ID of the form from which the entry value was submitted.
-
$field_id integer
The ID of the field from which the entry value was submitted.
-
$entry Entry Object
The current entry.
Examples
1. Display category names
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_entries_field_value', 'display_category_names', 10, 3 ); function display_category_names( $value, $form_id, $field_id ) { if ( $form_id != 3 || $field_id != 4 ) { 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_entries_field_value', function ( $value, $form_id, $field_id, $entry ) { $field = GFAPI::get_field( $form_id, $field_id ); $value_fields = array( 'checkbox', 'radio', 'select' ); if ( is_numeric( $field_id ) && in_array( $field->get_input_type(), $value_fields ) ) { $value = $field->get_value_entry_detail( RGFormsModel::get_lead_field_value( $entry, $field ), '', true, 'text' ); } return $value; }, 10, 4 );
3. File Upload Field
This example shows how you can define the markup returned for the file upload type field.
add_filter( 'gform_entries_field_value', 'file_upload_field_values', 10, 4 ); function file_upload_field_values( $value, $form_id, $field_id, $entry ) { $field = GFAPI::get_field( $form_id, $field_id ); if ( is_object( $field ) && $field->get_input_type() == 'fileupload' ) { $file_path = rgar( $entry, $field_id ); if ( $field->multipleFiles ) { $uploaded_files_arr = empty( $file_path ) ? array() : json_decode( $file_path, true ); $file_count = count( $uploaded_files_arr ); if ( $file_count > 1 ) { $value = empty( $uploaded_files_arr ) ? '' : sprintf( esc_html__( '%d files', 'gravityforms' ), count( $uploaded_files_arr ) ); return $value; } elseif ( $file_count == 1 ) { $file_path = current( $uploaded_files_arr ); } elseif ( $file_count == 0 ) { return ''; } } if ( ! empty( $file_path ) ) { $thumb = GFEntryList::get_icon_url( $file_path ); $file_path = esc_attr( $file_path ); $value = "<a href='$file_path' target='_blank' title='" . esc_attr__( 'Click to view', 'gravityforms' ) . "'><img src='$thumb'/></a>"; } } return $value; }
4. Link to user profile
This example shows how you can link the value of the entry created_by property to the user profile page.
add_filter( 'gform_entries_field_value', function ( $value, $form_id, $field_id, $entry ) { if ( $field_id === 'created_by' && ! empty( $value ) ) { $value = sprintf( '<a href="%s">%s</a>', esc_url( get_edit_user_link( $entry['created_by'] ) ), esc_html( $value ) ); } return $value; }, 10, 4 );
Placement
This code should be placed in the functions.php file of your active theme.
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).
Source Code
This filter is located in the following methods:
- GFEntryList::leads_page() in entry_list.php
- GFResults::get_default_field_results() in includes/addon/class-gf-results.php