Formidable Forms is my favorite form creation plugin for WordPress. It’s extremely flexible, and ideal for web developers.
The Situation
Recently I was asked to make a complex price calculator for a carpet cleaning company. The pricing worked as follows…
1 room cost $79
2 rooms cost $109
3 rooms cost $134
4 rooms cost $159
5 rooms cost $184
What We’re Making
Before launching into the detail let’s take a look at what we’ll be making…
Try changing the room number and see the result.
Why If Statements?
Since the pricing didn’t follow a predictable formula I needed to use if statements.
The Formidable Field Calculations Documentation doesn’t mention anything about using if statements, but after looking at other the examples I decided to do some experimentation…
if ( [carpet_rooms] == 1 ) { 79 }
The above code works. It basically says, if the rooms field is set to 1 the total will be set to 79. It’s simple but proves that if statements are possible.
By chaining if statements together, we can calculate the required pricing structure. Here’s what it looks like.
if ( [carpet_rooms] == 1 ) { 79 } else if ( [carpet_rooms] == 2 ) { 109 } else if ( [carpet_rooms] >= 3 ) { 109 + (25 * ([carpet_rooms] - 2) ) }

11 Comments
Great – this fills a hole in the official documentation. Thanks for posting. For other folk I had to evaluate 2 fields to set a discounted price and used the && operator as follows (where the numbers in square brackets are the field ID’s):
if ([279] == 260 && [278] == 1) { 245 } else if ([279] == 260 && [278] == 0) { 260 }
Thank you very much for sharing this! I did exactly the same thing in a plug-in called Calculated Field Form. I am happy to see this is possible with Formidableforms too since I want to switch.
nice one! works for me and a good addition to the doco!
You code doesn’t work for 1 or 2 rooms, do you have solution for that?
It has always been working for me, but I just realized that I’ve been using Firefox (where it worked flawlessly) but I was surprised to discover it wasn’t work in Chrome. Thanks for pointing that out! I must say, I am surprised I didn’t see that earlier.
In any case, it appears the fix is to use “else if” statements instead of just “if” statements.
I have updated to code above, accordingly.
Hi There
I am trying to make this work with testing fields with text strings in them and have done this for example:
if ( [1918] == “Farnham District” ) { [1956] } if ( [1918] == “Outside Farnham Scouts/Guides” ) { [1990] }
Have you any experience of using if statements with text strings? I as ask the statement above does not work and only returns a zero all the time.
Thanks
I did some testing, but I was unable to find a way to do that. Sorry.
Hi
Your guide really helped me a lot. Dont know why they didnt included in documentation. Thanks
WOW – Thank you – really helpful
Is any line need with this following code? If you embed any video tutorial about this, that will be more help for me. However, an awesome information. Thanks
Yes that’s a good point. I actually started to make a video about this but got busy before having the chance to finish it. I’ll try to wrap it up and post it here in the near future.