April 16, 2021: Added support for filtering via custom function.
November 9, 2020: Added support for excluding specific inputs of multi-input fields via the
:exclude
modifier.November 3, 2020: Migrated snippet to the Snippet Library.
January 27, 2020: Added
:nopricingfields
modifier to hide pricing fields from{all_fields}
output.September 5, 2019: Fixed notices generated in PHP7.3 by
continue
statements inside a foreach/switch.April 11, 2019: Updated priority of template replacement to avoid conflict with other merge tags replacement plugins.
The Gravity Forms {all_fields}
merge tag provides a super simple way to output all of the submitted form data but it’s notoriously difficult to customize.
This plugin provides templating support for the {all_fields}
merge tag. Huh? It means you can replace the markup generated by the merge tag with the contents of a file. This tutorial offers a solid starter template file too!
Getting Started
This tutorial assumes you’re running a recent version of Gravity Forms, that you already have the {all_fields}
merge tag implemented wherever you want, and that you ♥ Gravity Wiz.
![]() |
Download, install, and activate the plugin. |
![]() |
Download the sample template directory/file. Add the folder to your active theme’s root directory: /wp-content/themes/{your-theme}/
|
![]() |
Customize the template as desired. |
Template and Merge Tag Options
This plugin provides a few handy modifiers for controlling which template will be used to render the {all_fields}
merge tag.
Note: All template paths are relative to your theme’s root directory.
Default Templates
Merge Tag | Template |
---|---|
{all_fields} | /gravity-forms/all-fields.php |
Form-specific Template
Providing a form-specific template requires not changes to the merge tag. Simply append the targeted form ID to your template’s name. This template will now only be used with the merge tag is used in the context of the specified form.
Merge Tag | Template |
---|---|
{all_fields} | /gravity-forms/all-fields.php /gravity-forms/all-fields-1.php |
Custom Template
You may want to create a custom template that should only be applied to specific instances of the merge tag. The “template” modifier allows you to specify a custom template suffix.
Merge Tag | Template |
---|---|
{all_fields:template[custom]} | /gravity-forms/all-fields-{template}.php /gravity-forms/all-fields-custom.php |
No Template
You may want to create a generic template that applies to all instances of the merge tag by default and then disable that template to use the default Gravity Forms merge tag output in a few specific instances.
Merge Tag | Template |
---|---|
{all_fields:notemplate} | No template |
Hide Pricing Fields
Hide pricing fields (i.e. order summary) from the {all_fields}
output.
Merge Tag | Template |
---|---|
{all_fields:nopricingfields} | Hide pricing fields |
Field Filtering Modifier
These modifiers allow you to control which fields are output in the {all_fields}
merge tag without having to touch any code.
Please note: you only need the plugin installed to use these modifiers. You do not need to install the template files in your theme.
Merge Tag | Description |
---|---|
{all_fields:include[1,2]} | Include a field that is not included by default (i.e. HTML fields). |
{all_fields:exclude[3,4]} | Exclude a field that is included by default. |
{all_fields:filter[1,2]} | Only include the specified field IDs. This takes precedence over both the ‘include’ and ‘exclude’ modifiers. |
{all_fields:include[1,2],exclude[3]} | The :include and :exclude modifiers can be combined. |
GF Nested Forms Support
To filter which fields from a child form display in your {all_fields}
merge tag you can use the :filter modifier and the [Nested Form Field ID].[Child Field ID] format (e.g., 4.3; where 4 is the Nested Form field ID and 3 is the child field ID from the child form).
You can use the :include, :exclude, :filter, and :index modifiers on the Nested Form field to filter which child fields should be displayed.
Merge Tag | Description |
---|---|
{all_fields:filter[1,2,3.4,3.5]} | In this example, 1 and 2 are field IDs on the parent form. 3 is the Nested Form Field ID and 4 and 5 are field IDs on the child form. |
{Nested Form:1:filter[4,5]} | Show fields 4 and 5 from the child form for this Nested Form field. |
{Nested Form:1:index[0],filter[1]} | Show field 1 in the first child entry from the child form. :index must be paired with :filter. |
{Nested Form:1:index[-1],filter[1]}
to target the last entry and display the value from field 1.Excluding Specific Inputs Within a Field
Fields that contain multiple inputs, such as the Name field, can be excluded per-input by specifying the input ID. For example, to exclude the First Name, add .3
to the Field ID (e.g., 5.3; where 5 is the Name field).
This works for any field that contains multiple inputs, such as Name, Address, and Product. You can find the specific input IDs in Gravity Forms Documentation for Name and Address fields.
Merge Tag | Description |
---|---|
{all_fields:exclude[5.3]} | In this example, 5 is the field ID of a Name field. 3 is the First Name input ID. |
Filter and Exclude Via Custom Function
Custom functions can be used to identify fields for filtering. Using a custom modifier, the function should return an array of field IDs. For example, if you want to exclude fields with personal information from some instances of the {all_fields}
merge tag, you could specify a custom modifier value like so:
{all_fields:exclude[persInfoFields]}
And then create a custom function to identify the IDs of those fields.
add_filter( 'gwaft_modifier_value_persInfoFields', function() {
return array( 1, 2, 3 );
} );
Merge Tag | Description |
---|---|
{all_fields:exclude[customFunction]} | Exclude fields that are returned via customFunction. |
{all_fields:filter[customFunction]} | Show fields that are returned via customFunction. |
This is useful in circumstances when you need to use the {all_fields}
merge tag in multiple places and want to exclude the same fields in several contexts. Instead of having to copy the same string of field IDs to every place you’ve inserted the {all_fields}
merge tag, you can specify the custom function once and use the custom filter wherever you need it. If you want change or add to the excluded fields in the future, you simply update the custom filter and it will be applied everywhere the filter is used.
Customizing the Template
Ok, don’t let this section intimidate you. Here’s the TLDR; Loop through $items
, use $item['label']
for the field label, and $item['value']
for the field value. Here’s the simplest template you could have:
<ul>
<?php foreach( $items as $item ): ?>
<li>
<strong><?php echo $item['label']; ?><strong><br>
<?php echo $item['value']; ?>
</li>
<?php endforeach; ?>
</ul>
You’ll most likely want to use the sample template above as a starting point though as it takes care of a requirements to better align the template with Gravity Forms default All Fields functionality.
Digging Deeper
The {all_fields}
template works like any other WordPress template with one exception. There is a special $items
array available to you.
Each $item
contains a label, value, and field property. The label and value are the exact label and value that the default {all_fields}
merge tag would output. The field is the input-type-specific GF_Field object for the current field. This is useful when you want to alter the way a field is displayed depending on the field you’re working with.
Lastly, you have access to the current entry via the $entry
variable and the current form via the $form
variable. For more details on these variables, see the parameters section below.
Parameters
$items array
An array of items, each item containing the Gravity-Forms-formatted field label, field value and field object for the given field. The field label and field value are the same values that Gravity Forms outputs in the default
{all_fields}
merge tag.$entry Entry Object
The current Gravity Forms Entry object.
$form Form Object
The current Gravity Forms Form object.
FAQs
How do I hide Hidden fields from the {all_fields} merge tag?
You can use the :nohidden
merge tag modifier on the merge tag like this:
{all_fields:nohidden}
:nohidden
hides field output of fields using the Hidden field type. It doesn’t affect to fields set to a Visibility of Hidden.Hooks
Questions? Feedback?
What questions do you have? What features are missing? We’d like to make this into a more robust plugin and your feedback will be a big part of shaping the final product.
Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.
Hi I just saw the update on this and tried to use the nested forms filtering, but when I filter to [0] I get a list. When I filter to [1] or [2], or [3], etc they all work fine. How do I get a result from the first entry?
sorry I mean index. The filter part is working just fine, but when I index [0] I get a list instead of a single field
Hi Mike! This specific issue has been resolved in the latest version of GP Nested Forms (1.0-beta-9.16) which will be publicly available Tuesday 3/30/2021.
I’ve sent you an advanced copy of that build via email for the time being.
Have a great weekend :)
Would this allow me to export my form’s HTML blocks in my notification emails?
Hi Amanda,
Yes, the snippet can allow you to display the HTML blocks within notifications. Once you have the snippet installed, you should be able to use the “include” modifier to output the HTML fields in notifications. The include modifier is written in this format, {all_fields:include[1,2]}, where 1 and 2 are the IDs of the HTML fields you want to include in the notifications.
Best,
I would just love to see notification-email content wihtout the labels of the form fields or without the blue bars in the mail-notification.
Isn’t that possible even without this plugin?
Hello Karl, this is a great question. The all fields template will allow you to take over what is displayed when using the all fields merge tag. You can choose to display value only and not the label. As for blue bars, I am not sure I follow. If you mean each section that is shown and the css behind it , you can customize this within the custom templates we provided. 🙂