1

I have a form that will help a user build up a quote for fees to move house. The first page of the form will ask the user to select their nearest location from a drop down list, they will then enter the value of the house they wish to buy into a text field.

What I need to happen on the next page is to display the selected location from the drop down list and also the value they entered for the house, but also to display an estimated fee for purchasing the house.

The Fee is calculated by a series of ranges for each location, for example;

Location A
House Price | Fee
Up to 80000 | 100
80000 - 100000 | 200
Over 100000 | 300

Location B
House Price | Fee
Up to 80000 | 150
80000 - 100000 | 250
Over 100000 | 350

I have looked at various Form modules, but none of them do any kind of calculations. So I was wondering if anyone has done anything like this before with forms and calculations?

1

If you look at some forms modules (like FreeForm, Safecraker), you can have "entry_id" within the "return" parameter value and this entry id will be a segment at the returm page. Now you can use SQL via query module to get the posted / saved values for the further calculations.

Let's take an example with FreeForm:

In the FreeForm form tag you can have return parameter as return="template_group/template_name/%%entry_id%%"

and you can fetch the saved values with query module in the template "template_group/template_name" like

{exp:query sql="SELECT form_field_1 AS location, form_field_2 AS house_price, form_field_3 AS fee FROM exp_freeform_form_entries_1 WHERE entry_id='{segment_3}'"}

Calculation : {house_price} * {house_price} * {fee}
/***
There are some good add-on for mathmatical calculation. Although, you can do mathmatical calculation within SQL.
***/
{/exp:query}

Note: You need to have form_field_x associated with correct field id. Above example SQL will work with FreeForm v4.0+. For lowser version you can write SQL like:

{exp:query sql="SELECT location, house_price, fee FROM exp_freeform_entries WHERE entry_id='{segment_3}'"}
Calculation : {house_price} * {house_price} * {fee}
/***
There are some good add-on for mathmatical calculation. Although, you can do mathmatical calculation within SQL.
***/
{/exp:query}

In the same way, if you are using Safecraker, you can do the same without SQL query and just by writing channel entry tag, passing the parameter entry_id="{segment_3}"

Hope, it would help you.

0

I would assume the best way to do this would be JavaScript. I have built something similar in the past for various sites that needed industry specific calculators. Almost always you want to handle this with JavaScript, so this would be better covered outside of most EE add-ons.

I would just use jQuery to make life easy. If you needed to save the results, just use Safecracker and save the data to a channel after the JS calculates your totals. This method would work with any of the form add-ons though.

As far the JS syntax and logic, well that is outside the scope of my answer.

1
  • Thanks Justin for the quick reply. I was thinking of JavaScript, it's just not my forte really so was wondering if there was a way to handle it with some custom EE plugin. I'll take a look at jQuery. I guess I could then pass those values to some hidden inputs that could get saved with the SafeCracker form to a channel entry. Apr 28 '13 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.