|
 |
|
Building online calculations in your Formdesk form |
|
|
You can insert calculations into your Formdesk forms. This can, for example, be useful to calculate the total order price of an order form or to calculate the score in a questionnaire.
Anyone can create even complex calculations within a Formdesk form. It is very similar to the way you create formulas in a spreadsheet like Excel.
This document is really a Formdesk form (without a submit button) which includes calculations for demonstration purpose.
The examples are interactive so you can change the entries.
Below you will find an explanation on what calculations you can build in a Formdesk form and how it is done.
An example order form is available in which the ?-buttons explain how the calculations have been built up. |
|
This document discusses the following:
|
|
Where do I insert a calculation |
You insert a calculation in the same way that you insert any other item on a form. Therefore choose "Add Form Item" and then item type "Calculation". |
|
Identifiers |
Each question that you insert into your form will automatically be a provided a unique name that we call the question's Identifier.
You use these Identifiers in your calculation to refer to answers to a certain question. After all, the result of your calculation will always depend on given answers to question in your form of your user.
Calculations have an Identifier as well allowing you to refer to other calculations within a calculation. |
|
Calculations based on open questions |
Suppose you offer a product in your form of $ 25,--. Your user can enter the number of copies of this product he wants to order: |
|
|
We have assigned the Identifier product to the question for the number of copies.
The calculation for the total charge is:
[product] * 25
You can also create a calculation using more than one open question: |
|
|
The Identifiers of the questions/entry fields are Field1 and Field2.
The calculation is:
[Field1] + [Field2] |
|
Sub-calculations |
The calculations also have their own Identifier. This allows you to refer to other calculations from within your calculation.
Suppose you offer different products of different prices and that you want to calculate the order total. You could choose to directly calculate the order total but you can also choose to calculate a subtotal for each product first and subsequently sum up the subtotals.
No sub-calculations: |
|
|
The Identifiers of the questions are Product1, Product2 and Product3.
The calculation for the order total is:
( [product1] * 25 ) + ( [Product2] * 14.95 ) + ( [Product3] * 22.50 )
Using sub-calculations: |
|
|
The Identifiers of the sub-calculations are Total1, Total2 and Total3.
The calculation for the order total is:
[Total1] + [Total2] + [Total3] |
|
Conditional calculations / calculating based on multiple choice questions |
Your calculations can be based on other questions than open questions such as multiple choice questions. In such case you need to use conditional calculations.
The syntax for a conditional calculation is:
IF condition THEN value (ELSE value) ENDIF.
The condition must always contain an operator: '=' equals to, '!=' is not equal to, '<' smaller than, '>' greater than.
The value must always be numeric.
Yes/No question (single check box):
Suppose that you use a single check box to ask your user if he wants the products to be sent by express.
If you user ticks the box the subtotal must be increased by $ 10. |
|
|
The Identifier of the subtotal calculations is Subtotal.
The Identifier of the question if the product must be sent my express is Express.
The calculation for the order total is:
[Subtotal] + IF [express] = "Selected" THEN 10 ENDIF
The part IF [express] = "Selected" stands for: if the user selected the check box of the question of which the Identifier is Express....
A more compact syntax that you can use is IF [express] THEN ..... If you want to check whether the check bos is NOT selected you'd use IF [express] != "Selected" THEN ..... or IF ![express] THEN .....
Multiple choice, single answer question containing two options:
Suppose that you use a multiple choice question to ask if the ordered products must be sent COD (cash on delivery) or that they will be picked up. If you user chooses the COD option $ 10 must be added to the order total . |
|
|
The Identifier of the subtotal calculation is Subtotal.
The Identifier of the question for the shipping method is ShipMeth.
The calculation for the order total is:
[Subtotal] + IF [ShipMeth] = 1 THEN 10 ENDIF
The part IF [ShipMeth] = 1 stands for: if the user chooses the first option on the shipping method question....
You can also choose to refer to the option description:
[Subtotal] + IF [ShipMeth] = "COD" THEN 10 ENDIF
The downside is that de calculation would not work anymore after you change the option's description. From this point in this manual, we will only use the order number in the conditions. |
|
|
Multiple choice, single answer question using more than two options:
Suppose that in your form you use a multiple choice question to ask your user if he wants the products to be sent COD (add $ 5), by express ($ 10) or if he wants to pick up the products (free of charge).
If your user chooses one of the first two options the related extra charges need to be added to the order total. |
|
|
The Identifier of the subtotal calculation is Subtotal.
The Identifier of the multiple choice question is ShipMeth.
The calculation for the order total is:
[Subtotal] + IF [ShipMeth] = 1 THEN 5 ENDIF + IF [ShipMeth] = 2 THEN 10 ENDIF
Multiple choice, multiple answers question:
Suppose that you use a multiple choice question to offer additional service on the ordered product. You want to show the order total as well as the number of selected services: |
|
|
The Identifier of the multiple choice question is Services.
The calculation for the order total is:
IF [services] = 1 THEN 40 ENDIF + IF [services] = 2 THEN 55 ENDIF + IF [services] = 3 THEN 35 ENDIF + IF [services] = 4 THEN 60 ENDIF
The calculation for the number of selected additional services is:
IF [services] = 1 THEN 1 ENDIF + IF [services] = 2 THEN 1 ENDIF + IF [services] = 3 THEN 1 ENDIF + IF [services] = 4 THEN 1 ENDIF |
|
List boxes:
Building calculations based on list boxes is again done the same way as all multiple choice questions.
If you use the example of the multiple choice, single answer question the calculation will remain the same as well. |
|
|
The Identifier of the subtotal calculation is Subtotal.
The Identifier of the list box is ShipMeth.
The calculation of the order total is:
[Subtotal] + IF [ShipMeth] = 1 THEN 5 ENDIF + IF [ShipMeth] = 2 THEN 10 ENDIF |
|
Using 'AND' and 'OR':
If the result of a calculation depends on a combination of answers given by your user, you can use AND and OR in the condition part (between the IF and ENDIF).
In the above example shipment is free of charge if the value of the ordered product is more than $ 100. |
|
|
The Identifier of the subtotal is Subtotal.
The Identifier of the multiple choice question is ShipMeth.
The calculation of the shipping charges is:
IF [ShipMeth] = 2 AND [Subtotal] < 100 THEN 5 ENDIF + IF [ShipMeth] = 3 AND [Subtotal] < 100 THEN 10 ENDIF |
|
Multiple choice questions in which the values to be summed up are part of the options:
Some of the calculations used in the examples above could actually be built up much easier.
If the values to be summed are part of the options of a multiple choice question the calculation may exists of the Identifier only. Formdesk will search for the values within the options and sum them up.
Suppose you use a multiple choice question containing the name and price of your products. |
|
|
|
|
|
|
|
|
The Identifier of the multiple choice question is Fruit.
The calculation only contains the Identifier:
[Fruit]
Important: Formdesk will search for the FIRST value in the options. If you would have an option like '12 apples for $ 2.50' Formdesk would read 12 instead of 2.50. |
|
Calculations based on dates or times |
Dates
You can calculate the number of days between two given dates by substracting these dates: |
|
|
The Identifier of the starting date is DateStart and of the end date is DateEnd.
The calculation for the number of days is:
[DateEnd] - [DateStart] |
|
You can create calculations based on a fixed date by adding a date field to your form, for which you assign a default date. You can hide this question for your users. |
|
|
The Identifier of the date question is Date1. For the calculation we have added a date field with the Identifier Millennium to the form. For this field we assigned the default value of 01/01/2000. This field is placed a few lines below. You'd normally hide these fields from your users which we didn't, for the sake of this explenation.
The calculation is:
[Date1] - [Millennium] |
|
You can use the same method to calculate based on today's date. Just add a date field that you set to 'default to date of form request'. Hide the item so your users won't see it. |
|
|
The function Today() results in today's date. The Identifier of the date field that defaults to 01/01/2000 is Millennium.
The calculation is:
Today() - [Millennium] |
|
|
|
|
TIP: These date fields can be hidden for your users ! |
|
|
You can also use conditions for your date calculations. For example, to calculate the price of a entrance ticket of $ 13.50 that is only $ 10 for children younger than 10 and people older than 65: |
|
|
|
|
|
|
|
|
|
|
The Identifier of the question for the date of birth is BirthDate.
The calculation of the age is:
FLOOR( (Today() - [BirthDate]) / 365.25)
In order to prevent that an unreal high age is calculated, we should check if the field is not empty and otherwise, set the age to 0. The calculation will then be:
IF [BirthDate] = "" THEN 0 ELSE FLOOR( (Today() - [BirthDate]) / 365.25) ENDIF
The Identifier of the age calculation is age.
The calculation for the entrance fee is:
IF [Age]> 64 OR [Age] < 10 THEN 10 ELSE 13.50 ENDIF |
|
|
Times
You calculate the number of minutes between two specified times by substraction: |
|
|
The Identifier of the starting time is TimeStart and of the ending time TimeEnd.
The calculation for the number of minutes is:
[TimeEnd] - [TimeStart] |
|
|
Calculation functions |
Next to basic operators used to add (+), substract (-), multiply (*) and divide (/) you can also use the following functions within advanced calculations.
|
Ceil
Rounds up a decimal number.
|
|
|
Ceil( [value] ) |
|
Floor
Rounds down a decimal number. |
|
|
Floor( [value] ) |
|
Round
Rounds a decimal number to the nearest integer.
|
|
|
Round( [value] ) |
|
Sqrt
Calculates the square root of a number. |
|
|
Sqrt( [value] ) |
|
Pow
To raise a number to a given power. |
|
|
Pow( [value1], [value2] ) |
|
Min
Returns the smallest number within a number sequence. |
|
|
Min( [value1], [value2], [value3] ) |
|
Max
Returns the largest number within a number sequence. |
|
|
|
Random() * 100 |
|
Year, Month en Day
The functions Year(), Month() en Day() result in the year, the month and the day of a date field. If you omit the parameter, today's date will be used. |
|
|
Year( [value] ) / Month( [value] ) / Day( [value] ) |
|
Today()
The function Today() results in the Julian day number (and time) of today's date. This also counts for date fields you refer to within a calculation. |
|
|
Today() |
|
TIP: If you are familiar with javascript functions, you can use any javascript function with Math.function(). |
|
View references |
Withihn the Questions tab you can visualize the references to answers of other form items of the calculations that you defined. In the menu of one or more selected items choose the option 'Show references' or, to view the references of all items, click the icon in the toolbar. Blue arrows will show which items refer to which items within your calculations. |
|
 |
|
Remarks |
You can hide calculations. This can be very useful for sub calculations. Hidden calculations can be shown in the (email)messages upon form completion.
Please note that a malicious person with some technical knowledge can influence the outcome of the calculation. If your user has any reason for this, always check the calculation yourself on receipt. |
|
|
|
|
|
|
|