gform_entry_field_value

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

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>';
}

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 );

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 );

Phone Field – International (formatted)

The following example shows how you can change the value displayed on the entry detail for the International (formatted) type Phone field with Gravity Forms 3.0+.

add_filter( 'gform_entry_field_value', function ( $value, $field, $entry ) {
	if ( empty( $value ) || ! $field instanceof GF_Field_Phone ) {
		return $value;
	}

	$entry_value = rgar( $entry, $field->id );
	if ( ! GFCommon::is_json( $entry_value ) ) {
		return $value;
	}

	$decoded = json_decode( $entry_value, true );
	if ( empty( $decoded['formatted'] ) ) {
		return $value;
	}

	// Possible keys are: formatted, national, country, e164

	return $decoded['formatted'];
}, 10, 3 );

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 can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFEntryDetail::lead_detail_grid() in entry_detail.php.