How to show label instead of value in entries for specific field and form?

I want to add a filter so that when I go to Entries on a specific form it shows me the label for a specific field, instead of the value. For example, I have a field that is -

Select
Value: 1
Label: Yes

I want to show “Yes”

This is the code I am using that adds a filter so that it shows the label instead of the value for Select 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(
      '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 );

This works but it does it for all select fields on all forms.

How can I add a conditional so that it only does it for ID: 15 on Form: 1 ?

Hey,

You can simply add a conditional check for the form ID and form field so the function will only trigger on a specific form and field.

add_filter( 'gform_entries_field_value', function ( $value, $form_id, $field_id, $entry ) {

    // Check your form ID and field ID
    if ( $form_id == 1 && $field_id == 15 ) {
        $field        = GFAPI::get_field( $form_id, $field_id );
        $value_fields = array(
            '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 );

Give it a try, and let me know how that goes! :smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.