Calculations with Nested Forms

This article requires the GP Nested Forms perk. Buy Gravity Perks today to get this perk plus 32 other galatic Gravity Forms plugins!


One of the most powerful features of GF Nested Forms is its ability to perform calculations on the Parent Form with data in the Child Form. In this tutorial we’re going to do a deep dive into the different calculations and cover some common use cases for those calculations. Let’s begin.

  1. Overview
  2. :count
    1. Numbering Entries
    2. Calculated Quantities
  3. :total
    1. Collecting a Single Payment for Multiple Orders
  4. :sum
    1. Sum the Number of Reserved Seats
  5. Wrapping Up


The :count merge tag modifier returns the total number of child entries attached to the Nested Form field. If there are two child entries submitted for a Nested Form field, this merge tag will return 2.


Numbering Entries

A common use for the :count modifier is to attach numbering to the Nested Forms entries themselves. For example, an order form with line items.

You can achieve this numbering sequence by utilizing a couple of Nested Forms specific merge tags and Number fields. Here’s how you would set it up:

In your Parent form, add a Number field, enable calculation, and use the :count merge tag modifier in the calculation to count the number of Nested Form entries. Set this field as hidden.

In the Nested Form, add a Number field and in its Default Value enter the {Parent} merge tag to pull the value from our newly-added Number field into the Child Form.

That’s it. When Add Entry is clicked, the modal will appear and the {Parent} merge tag will pull in the current entry count into the Child Form. For the first entry, that will be 0. Once a new entry is added to the form, the count on the Parent form goes up by 1. The next child entry will then be numbered 1 and so on.

To start the numbering at 1, add +1 to the Parent form calculation.

Calculated Quantities

Another use for the :count merge tag modifier is to calculate quantities based on the number of Nested Form entries.

For example, say you have a Player sign up form and you want to charge a certain amount for each player on the team and you want to offer quantity-based discounts with GF Conditional Pricing. This is made possible by adding GF Copy Cat to the mix. Here’s how you would set that up:

Add a Number field to the Parent form, enable calculation, and enter only the Nested Form merge tag with the :count modifier as the calculation. Set this field as hidden.

Add a Product field to the form. Note the Field ID for this field.

Within the Appearance tab of the Number field, enter the Copy Cat Custom CSS class to copy the calculated Number field’s value to the Quantity of the Product field. The syntax for this is the following:

copy-x-to-y.3 where x is the Field ID for the Number field and y is the Field ID for the Product field. The .3 tells Copy Cat to copy into the Quantity portion of the Product field.

You’re well set. When a customer adds an entry to the Nested Form, the merge tag will populate your hidden Number field and Copy Cat will copy that number to the Product field’s quantity. You can then use Conditional Pricing to offer bulk pricing.

Users can edit the quantity in the Product field. To avoid this, either hide the Product field or use GF Read Only.


The :total merge tag modifier returns the sum of all child entry order totals. For example, if Child Entry #1 has a total of $10 and Child Entry #2 has a total of $25, this merge tag would return 35.


In order to use this merge tag modifier, the Child form must contain at least one Product field. It ignores Number fields.

Collecting a Single Payment for Multiple Orders

With the :total merge tag modifier, you can add any number of Products to a Child form and only have to collect payment once in the Parent form. This simplifies the purchasing process and gives your customers a better user experience. Setting this up is simple:

  1. Add a Product field to your Child form and set appropriate Price and Quantity settings.
  2. Add a Product field to your Parent form, set its Type to Calculation and disable Quantity. For the Calculation, insert the merge tag for the Nested Form with the :total merge tag modifier.

That’s all there is to it. The Product totals for all Child Entries will be passed to the Product field in the Parent form, and you can collect payment one time in the Parent form using any of the Gravity Forms Payment Add-Ons.


The :sum merge tag modifier returns the sum of the specified target field’s value from each child entry. For example, if you have a Number field inside your Nested Form and Child Entry #1 has a value of 4 and Child Entry #2 has a value of 3, this merge tag will return 7.

The syntax for this calculation is a little more complicated than the others. It requires you to specify exactly which field in the Child Form you want to sum, preceded by an =. For example, let’s say you have a Nested Form Field in your Parent Form with an ID of 1. Inside your Child Form, there is a Number field with an ID of 2. The merge tag you would use in the Calculation in the Parent Form is this:


Sum the Number of Reserved Seats

With the :sum merge tag modifier you can add up the sum of any field, and a practical example of that is if you’re trying to determine how many seats are required for an event.

Let’s say you have a form that will be used for different companies to register attendees for an industry awards banquet. Each company can reserve a certain number of attendees and those attendees can optionally bring a guest.

Nested Forms can handle registering multiple attendees in a single form, and we can use the :sum merge tag to figure out exactly how many seats are needed. Let’s get started.

Add a Drop Down Field in your Child form to indicate whether the attendee will bring a guest. Check show values and set the values to 2 for “Yes” and 1 for “No”. Note the Field ID, we’ll be using it later.

In your Parent Form, add a Number field, Enable Calculation, and insert the Sum merge tag. Enter the Field ID noted above after the equals.

That’s all there is to it. The :sum merge tag modifier will automatically sum up the value from the Drop Down field into the Number field on the Parent Form.

Wrapping Up

As you can see, calculations in Nested Forms offer tons of flexibility for passing values from the Child Form to the Parent Forms. We’ve talked about some common use cases we’ve seen from our customers, but if there’s anything we haven’t covered, please let us know in the comments. We love hearing all of the interesting ways our customers use our Perks!

Leave a Comment

Your email address will not be published. Required fields are marked *