Gravity Forms Calculations

We had an interesting and challenging request come up recently when setting up a Gravity Form (our preferred WordPress form plugin thanks to its extensibility and ease of use) for a client. The main requirement was to have two separate values for the same item in a form. A sponsorship level would have both a cost and a fair market value. This ended up being more complex than it at first appeared. We needed to do some Gravity Forms calculations to fulfill the requirements.

The requirements:

  • A drop down form field showing different sponsorship level options.
  • A quantity associated with the sponsorship levels – the user could choose two $500 sponsorships, for example.
  • A “fair market value” (FMV) amount associated with each level, for tax purposes. As an example, a $500 sponsorship level might be equal to a fair market value of $150. So we needed both numbers, the sponsorship cost and the fair market value price, associated with each sponsorship level.
  • The sponsorship amount and the FMV amount both needed to show up in the email notification to the new sponsor.

Information & methods we considered:

  • We can use conditionals inside notification emails in Gravity Forms, as explained here by Gravity Wiz. This could allow us to only display certain fields inside the notification instead of leaving blank spaces. We ended up not needing to use this option, but it’s a good fit for other situations.
  • The client’s website uses the Gravity View plugin, which can do math – but not outside of the “Views.” So we couldn’t use this to perform calculations inside forms or notifications. This could be useful for displaying form entries on the front end of a website instead.
  • We considered using the fair market value as the product’s “value” with the form (different from its “price”), to then perform a hidden calculation. This did not work because the notification displays the field *price* instead of the field *value*, and we wanted to display the FMV to the sponsor in the email notification. Furthermore, the form displays the “value” as the product’s name inside the Gravity Form entries area on the admin side, which makes the entry form harder to read.

Our Solution:

After a lot of thought and searching for the best way to handle this, IT Support Guides pointed us in the right direction with their post about advanced calculations. This was a more convoluted solution than we would have liked, but it got the job done. Here’s how.

In the Gravity Form itself, we:

  • Added a separate “Number” field for each Fair Market Value amount
  • Enabled calculation for each of the Fair Market Value amount fields, and calculated the quantity {Number of sponsorships: 25} times the FMV (below, $1160)
  • Set “Visibility” to “Hidden” for this field, so that it isn’t displayed to the form user
  • Checked “enable conditional logic” and had each field display only if the related sponsorship level was chosen. This field is already hidden in the form on the front end of the web page, but this way, the other FMV fields won’t even display in the source code. This will prevent the unused fields from showing up in our email notifications, as we’ll see further down.

In the Gravity Form Email Notification:

  • We added this text in the message area, using the merge fields:
    For your records, in exchange for your {Total:9} sponsorship, you have received ${Fair Market Value (Double Platinum):26}{Fair Market Value (Music Producer):27}{Fair Market Value (Gold Album):28}{Fair Market Value (Silver Album):29}{Fair Market Value (Garage Band):30}{Fair Market Value (VIP Tickets):31} in goods/services.

Thanks to the conditionals we placed in the Number fields for the FMVs in the forms, the FMV Number fields for unused sponsorship levels will not show up. So we can list the FMV fields one after the other in the notification email, because only the one that is actually being used will show up:

Gravity Form hidden fields

Resulting email:

Gravity Form email

Check out all Gravity Forms has to offer.

See our featured website design work

Check out some of the beautiful websites we’ve built for over 2,000 clients.

We offer WordPress support & maintenance

Shake the stress of ongoing maintenance with plans supported by our team of WordPress experts.

Related articles