bookmark_bordergform_entries_field_value

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 (ie ‘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 (example output: http://grab.by/7UWT).

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 ) {
    $form         = GFAPI::get_form( $form_id );
    $field        = RGFormsModel::get_field( $form, $field_id );
    $value_fields = array(
        'checkbox',
        'radio',
        'select'
    );

    if ( is_integer( $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 ) {
	$form  = GFAPI::get_form( $form_id );
	$field = RGFormsModel::get_field( $form, $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;
}

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