Hide fields from entry view

Hello.

Is it possible to hide a field when viewing an entry in the backend? I have a few hidden fields that gather information such as the logged in user’s email to populate a custom post type on submission that I would not like to be seen.

Any ideas?

Hi,

The solution below is not exactly to hide the fields but to protect their values.

To protect sensitive data from being displayed in the form entries, you can intercept the values of specific fields before they are sent to the front end.

You can leverage the gform_entries_field_value and gform_entry_field_value filters, respectively.

The gform_entries_field_value filter allows you to intercept the field value in the Entries List Page. Documentation: https://docs.gravityforms.com/gform_entries_field_value/.

The gform_entry_field_value filter allows you to intercept the field value in the individual entry post. Documentation: https://docs.gravityforms.com/gform_entry_field_value/.

The approach is as follows:

  1. Evaluate a specific field by its ID.
  2. When the ID is matched, return a different value.

Here is a sample snippet to protect the field value in the Entries List.

add_filter( 'gform_entries_field_value', 'protect_specific_field_from_entries_list', 10, 4 );
function protect_specific_field_from_entries_list( $value, $form_id, $field_id, $entry ) {
    // Replace field_id with the ID of the field you want to hide
    if ( $field_id == 17 ) {
        return 'PROTECTED'; 
    }
    
    return $value;
}

Here is a sample snippet to protect the field value on the individual entry post:

add_filter( 'gform_entry_field_value', 'protect_field_value_in_entry_detail', 10, 4 );
function protect_field_value_in_entry_detail( $value, $field, $entry, $form ) {
    // Replace $field->id with the ID of the field you want to protect.
    
    if ( $field->id == 17 ) {
        
        $field->label = 'PROTECTED';
        return 'PROTECTED';
    }
    
    return $value;
}

Please note there is a difference in the arguments passed to the filter. The gform_entry_field_value filter gets the $field object. That’s why the field ID is accessed as a property. This allows you to access the field label and change it to a custom value in the Entry detail.

On the contrary, the gform_entries_field_value filter gets directly the $field_id value.

The results should be as follows:

image

image

If you inspect the elements in the browser’s dev console, the rendered values correspond to your new custom values.

image

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

A couple ideas if you are needing to use this in a wide variety of forms / cases:

  • gform_field_advanced_settings could allow you to add your own setting for all fields to define whether it should be accessible or not. The filter you have above could check that from the $field parameter.

  • That could lead you to defining visibility of the values by role, which is what Gravity Flow was designed to do exceptionally well. Whether during active steps (by defining an assignee and which fields are editable or display such as on a user input step), or for submitter or users with particular permissions via the start and complete step settings.

  • If using Gravity Flow in that way, you’d adjust the capabilities of what users can access the Forms > Entries screen with the gravityforms_edit_entries capability being removed. Flow gives you option for users to access via the admin dashboard or via blocks on the front-end.

The advanced setting could also be read from gravityflow_editable_fields, gravityflow_workflow_detail_display_fields and gravityflow_display_field_choices so that no protected fields could ever be chosen for edit/display if you really need to lock things down.

Regards,
Jamie