bookmark_bordergform_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

    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 (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_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 ) {
    $value_fields = array(
        'checkbox',
        'radio',
        'select'
    );

    if ( 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 Uploads

This example shows how you could display uploaded images.

add_filter( 'gform_entry_field_value', function ( $value, $field, $entry, $form ) {
	if ( $field->get_input_type() == 'fileupload' && $field->multipleFiles && ! empty( $value ) ) {
		$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 );

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 GFEntryDetail::lead_detail_grid() in entry_detail.php