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:
- Evaluate a specific field by its ID.
- 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:
If you inspect the elements in the browser’s dev console, the rendered values correspond to your new custom values.