Complex field calculations in Formidable

At work we use a WordPress plugin called Formidable whenever we need to build a complex form. One of the reasons we love Formidable so much is because of it’s flexibility/versatility. You can easily create custom multiple custom views to display form contents in any way you want for any type of user/visitor. Currently, I am in the process of building out an ROI Calculator for one of our clients. Building the form was fairly easy (although there are well over 50 questions!), however building the results pages was a little more than I bargained for. One of the challenges I ran into is that I need to present a results table to a user with calculations related to other responses in the form.

Here is a snippet from the form to help give you some context.

As you can see above, the Total Initial Training costs field is a calculated field. It takes the values from 22, 23 and 24 uses them to calculate Total Initial Training Costs. That is the easy part. Next the user is asked whether this is an expense that should be depreciated. In order to build the results page for this form I need to check whether that answer is yes or no. If it is yes then I need to populate another hidden field with the total training costs value. If it is no, then I will populate it with zero.

I was originally trying to pull this off in the view but it got really messy really quick so that’s when I decided to just add more hidden calculated fields with the results I needed. Unfortunately the Formidable documentation doesn’t have much information on complex calculations in fields, but through some searching I found that they will basically accept any Javascript. With that knowledge it would seem that I could just do this in the field:

if([655] === "Yes"){[587]}else{0}

In the snippet above [662] is the id of the yes/no field and [661] is the id of the total field. It was a little frustrating because this did not work the way I expected and I had to do some trial and error. I discovered that in order to use the values from a dropdown in this way, I had to assign them separate values. In this case I used 1 and 0. Here is what that looks like:

You can see the id is 655 for this field. So now I can rewrite my calculated field to look like this:

Leave a Comment

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

Scroll to Top