Protect specific fields in form entries on Gravity Forms.

Let’s say you have a form that collects sensitive data like email address, user government ID, etc.

By default, when an entry is submitted all those details are exposed in the individual entry on the WordPress admin.

Let’s also say that you delegate some tasks on your website and have collaborators that can access the form entries in the WordPress admin.

You may probably want to restrict some entry details from them, to protect your user’s privacy.

Something you can do is filter the field values displayed for each entry.

You can intercept the field value and change it to whatever you prefer.

Gravity Forms provide two useful filters for this matter:

gform_entries_field_value. https://docs.gravityforms.com/gform_entries_field_value/.

gform_entry_field_value. https://docs.gravityforms.com/gform_entry_field_value/.

The difference between each is that the first one, gform_entries_field_value, intercepts the field values in the Entries list.

The second one, gform_entry_field_value, filters the field values in the Individual entry page.

Here is a sample snippet to protect the field value on 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;
}

You can reference the field or fields by the field ID.

Then, on every match, return a custom 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;
}

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

Check the documentation links below:

Remove the upload percentage from the File Upload field in Gravity Forms.

In Gravity Forms, you can add the File Upload field to allow users to upload documents when submitting your form.

It can be used for virtually any file type, from text documents to image files, etc.

Gravity Forms, like any form software, validates unfilled required fields. If a user tries to submit a form without completing the required fields, the form page will reload with an error.

If the user uploaded a file during that incorrect submission, the file will persist in the upload field through the page refresh with the error.

But, a percentage number will suffix the filename in the upload field.

Something like this:

If there were no problems with the upload during the form error evaluation, the percentage would be equal to 100%.

That means the file was completely uploaded with the upload field and is ready.

If you complete the form, the file will be submitted along with any other data entered by the user.

What if you want to remove that percentage from the upload field?

So, even if the form page is reloaded when errors are found, the percentage is not displayed.

This is possible with a filter called gform_file_upload_markup.

Documentation here: https://docs.gravityforms.com/gform_file_upload_markup/.

First, we must understand that the upload percentage is part of the File Upload field markup.

The upload percentage is an HTML element under a span tag with its own CSS class, gfield_fileupload_percent.

You could add a quick CSS snippet and hide the upload percentage with display: none, like so:

.gfield_fileupload_percent{
     display:none;
}

And that works well. But it is only a cosmetic effect.

The percentage is still there in the DOM.

An alternative method is removing the upload percentage from the File Upload field markup before rendering it in the front end.

That’s where the gform_file_upload_markup filter comes into play.

The filter in question helps you intercept the File Upload field markup in Gravity Forms.

The challenge is that a long array of markup is associated with that filter.

If not handled carefully, you could mess up the File Upload field markup.

To solve this issue, you can leverage PHP’s string manipulation capabilities.

In this instance, you can check in the filter for the existence of the upload percentage field in the File Upload markup.

If it does not exist, abort further execution and return the File Upload field markup as is.

But if it is detected, then continue the execution: fiend the start and end of the span element with the CSS class gfield_fileupload_percent assigned to it.

Then, remove the selected element from the File Upload field markup.

Below is an example snippet that would achieve just that:

add_filter( 'gform_file_upload_markup', 'remove_gfield_fileupload_percent', 10, 4 );

function remove_gfield_fileupload_percent( $file_upload_markup, $file_info, $form_id, $field_id ) {
    // Check for the presence of 'gfield_fileupload_percent' in the markup.
    $percent_pos = strpos( $file_upload_markup, 'gfield_fileupload_percent' );
    if ( $percent_pos === false ) {
        // If 'gfield_fileupload_percent' is not found, return the current markup as is.
        return $file_upload_markup;
    }

    // Find the start of the span containing 'gfield_fileupload_percent'.
    $start_pos = strrpos( substr( $file_upload_markup, 0, $percent_pos ), '<span' );

    // Find the end of the span.
    $end_pos = strpos( $file_upload_markup, '</span>', $percent_pos ) + 7;

    // Remove the span containing 'gfield_fileupload_percent'.
    $file_upload_markup = substr_replace( $file_upload_markup, '', $start_pos, $end_pos - $start_pos );

    return $file_upload_markup;
}

This code should go in your theme’s functions.php or your preferred code snippets plugin.

The code can be used as is without the need for modification.

The exception would be that you want to add any custom conditions, etc.

Until next time!