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…

If Statement Calculator Demo

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 } if ( [carpet_rooms] == 2 ) { 109 } if ( [carpet_rooms] >= 3 ) { 109 + (25 * ([carpet_rooms] - 2) ) }
  • Mh Shamim says:

    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

    • Administrator says:

      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.

Leave a Reply

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