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) ) }
  • Steve Bragg says:

    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.


  • Harsh says:

    Your guide really helped me a lot. Dont know why they didnt included in documentation. Thanks

  • HF says:

    WOW – Thank you – really helpful

  • 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 *