The Problem
A Gravity Forms user asked if it was possible to leave personal information out of notifications that use the {all_fields} merge tag.
He was collecting sensitive details, like a date of birth and an ID number, and didn’t want them sent around in plain-text email. But he still wanted the convenience of {all_fields} for everything else.
The Solution
Gravity Forms doesn’t have a built-in way to exclude specific fields from {all_fields}. The free Gravity Wiz snippet library has two pieces that solve it together:
- All Fields Template adds modifiers to
{all_fields}, includingexclude. - Exclude Fields With Personal Information (below) creates a named list of fields you can reuse in any notification.
Step 1: Install the All Fields Template Snippet
Add the Gravity Wiz All Fields Template snippet to your site, either with a code snippet plugin like WPCodeBox or as a small custom plugin. The snippet below depends on it.
On its own, it already lets you exclude fields by ID: {all_fields:exclude[3,5,8]}. That works fine for one form. The next step makes it easier to reuse.
Step 2: Add the Personal Info Snippet
This snippet creates a custom modifier called persInfoFields that stands for a list of field IDs:
/**
* Gravity Wiz // Gravity Forms // Exclude Fields With Personal Information
*
* Excludes fields with personal information from {all_fields} when you use
* the custom modifier: {all_fields:exclude[persInfoFields]}.
*/
add_filter( 'gwaft_modifier_value_persInfoFields', function() {
return array( 1, 2, 3 );
} );
Source: Gravity Wiz snippet library on GitHub.
How to Use This Code
- Change
array( 1, 2, 3 )to the IDs of the fields you want to keep out of emails. You’ll find each field’s ID in the form editor, next to the field label. - Open Form Settings → Notifications and edit the notification.
- Replace
{all_fields}in the message with{all_fields:exclude[persInfoFields]}. - Submit a test entry and check that the excluded fields are missing from the email.
The data is still saved in the entry, so you can see it in the WordPress admin. It just isn’t sent by email.
Things to Keep in Mind
- The field IDs apply to every form. If you use the modifier on several forms, make sure the IDs match the right fields on each, or use plain
exclude[...]with IDs per notification. - Excluding fields from email doesn’t make the rest of the email secure. For truly sensitive data, consider not emailing it at all and linking to the entry instead.
Need More Help?
If you still need help, use the chat or leave a comment below and we’ll get back to you.
Comments