Dynamic Configuration with Formulas


Introduction

The formula engine introduces smart processing to FormAssembly. Configuration options like email templates or “Thank-You” messages can be scripted and interact with submitted data.

The syntax is very similar to Excel  formulas. Here’s an example that could be used in an auto-responder email template:

Dear @IF(%%tfa_salutation%%="Mr.","Sir","Madam")

  • @IF(condition, statement_if_true, statement_if_false) is a function. It will be interpreted by the engine and replaced with the result of the evaluation.
  • %%tfa_salutation%% is the alias for the ‘Salutation’ field in the web form (here, a drop down menu with just “Mr.” and “Ms.”).

In plain English, this tests the submitted value for the ‘Salutation’ field. If it is “Mr.”, the email will include “Dear Sir”, otherwise it will be “Dear Madam”.

Note: The formula engine deals with post-submission processing only. It does not modify the submitted data, and can not be used inside the form itself. For calculated fields within the form, see Form Calculations.

Form Field Aliases

You can reference any field in your form using the alias syntax, which is the internal field name surrounded by two percent signs (e.g. %%field_name%%). The alias will be replaced with the actual value submitted with the form when the formula is evaluated.

Here’s another example you could use in the Auto-Responder:

Dear %%tfa_salutation%% %%tfa_lastname%%, ...

This will be translated for instance to “Dear Mr. Smith,” or “Dear Ms. John,”.

Alias List

Field aliases vary from form to form. To see the list of aliases for your form, go to the forms tab, select the form in the list and go to the notifications tab. At the bottom of this tab, click the “Show the list of available aliases for this form” link. The aliases page is also accessible from other places in the application, where formulas and aliases can be used.

Note: The formula engine also supports the {!form_field} notation used in Salesforce.
{!form_field} and %%form_field%% are equivalent.

Functions

The engine supports most functions found in MS Excel. The function must be spelled in uppercase and start with the ‘@’ character.

Here’s a list of the most useful functions:

Logic
@IF @IF(condition,when_true,when_false)
Performs a logical test and returns either the second parameter (if true) or the third parameter (if false).
Example:
@IF(%%field_a%%>5,"GOOD","NOT ENOUGH")
@AND @AND(condition 1,condition 2)
Returns TRUE if both conditions are true, FALSE otherwise (logical AND).
Example:
@IF((@AND(%%field_a%%>5,%%field_b%%>10)),"OK","NOT OK")
@OR @OR(condition 1,condition 2)
Returns TRUE if at least one condition is true, FALSE if all conditions are false (logical OR).
Example:
@IF((@OR(%%field_a%%>5,%%field_b%%>10)),when_true,when_false)
@NOT @NOT(condition)
Returns TRUE if at the condition is false, FALSE otherwise (logical NOT).
Example:
@IF((@NOT(%%field_a%%>5)),"OK","NOT OK")
Arithmetic
@COMPUTE @COMPUTE(%%field_A%%+%%field_B%%)
Performs arithmetic calculations on form fields.
@MAX @MAX(number1,number2,...)
Returns the largest value from the numbers provided.
@MIN @MIN(number1,number2,...)
Returns the smallest value from the numbers provided.
@ROUND @ROUND(number,decimal_places)
Returns a number rounded to a specified number of decimal places.
String Operations
@CONCATENATE @CONCATENATE(string,string,...)
Joins 2 or more strings together.
Example:
@CONCATENATE(%%tfa_firstname%%," ",%%tfa_lastname%%)
@LEFT @LEFT(text, number_of_characters )
Extract a number of characters from a string, starting from the left.
Example:
@LEFT(%%field_a%%,5)
@RIGHT @RIGHT(text, number_of_characters )
Extract a number of characters from a string, starting from the right.
Example:
@RIGHT(%%field_a%%,5)
@MID @MID( text, start_position, number_of_characters )
Extract a number of characters starting at any position.
@FIND @FIND( text1, text2,start_position)
Returns the location of a substring in a string (case-sensitive).  Returns #VALUE! if string not found.
Example:
@MID(%%tfa_email%%,@COMPUTE(@FIND("@",%%tfa_email%%)+1),
@COMPUTE(@FIND(".",%%tfa_email%%)-@FIND("@",%%tfa_email%%))-1)
(Returns the domain part of an email address).
Date & Time
@LOCALNOW @LOCALNOW()
Returns the current date and time according to your language and time-zone settings.
@LOCALTODAY @LOCALTODAY()
Returns the current date according to your language and time-zone settings.
@NOW @NOW()
Returns the current date as a timestamp. This can be passed to other date functions to extract the day, month or year.
@YEAR @YEAR(date_value)
Returns a four-digit year given a valid date.
Example:
@YEAR(@NOW)

Comparison Operators

A comparison operator can be used to compare two values in a @IF statement. The result is a logical value, either TRUE or FALSE.

Operator Name Example
= Equal to @IF(%%field_a%%="A",when_true,when_false)
> Greater than @IF(%%field_a%%>5,when_true,when_false)
< Less than @IF(%%field_a%%<5,when_true,when_false)
>= Greater than or equal to @IF(%%field_a%%>=5,when_true,when_false)
<= Lower than or equal to @IF(%%field_a%%<=5,when_true,when_false)
<> Not equal @IF(%%field_a%%<>5,when_true,when_false)

Examples

How to redirect your visitor based on a field value

  1. Go to “My Forms” and click on the form you need to configure. This opens the form properties panel on the right-hand side.
  2. Click on the “Notifications” tab.
  3. In the “redirect to this page” field, instead of typing in the web address (URL) of the page, enter a formula.The syntax should look like this:

    @IF(%%tfa_field%%="Page 1", "http://your.site.tld/page_1.html",

    @IF(%%tfa_field%%="Page 2", "http://your.site.tld/page_2.html",

    @IF(%%tfa_field%%="Page 3", "http://your.site.tld/page_3.html",

    "http://your.site.tld/default_page.html"
    )))

Here’s the explanation for each part:

@IF The logical function used to test the value of a field.
Note that the @IF statements are nested to perform the equivalent of a if/else/otherwise logical construct.
%%tfa_field%% The alias of the field you need to test. The actual name will be different for your form.
To find the correct alias, click on the link at the bottom of the Notifications tab.
“Page 1″ The expected value. If you are testing a multiple-choice field, you must enter the choice value.
To find the choice values for an alias, click on the link at the bottom of the Notifications tab.
“http://your.site.tld/page_1.html” This is the page where the user will be redirected if “Page 1″ was selected.

Testing checkboxes values

Checkbox fields are handled a bit differently, as each choice must be checked separately.

Assuming the choice aliases are tfa_blue and tfa_red. You can do:

@IF(%%tfa_blue%%="Blue", "You've selected blue", "");
@IF(%%tfa_red%%="Red", "You've selected red", "");

Restrictions

  • Formulas are available in the Professional Plan only for FormAssembly.com customers. For FormAssembly On-Site users, formulas usage may be restricted on a role by role basis.