The Fields Counter helps you to count how many fields from a field set satisfy certain conditions. This may be used in surveys and with a repeating field set.
Syntax:
output_field - the field where the result will be put. You can use it in any page or template just like any other field: {#output_field#}
regular_expression - counts the fields that fit this expression. See below for a detailed explanation.
fieldN = valueN - field conditions, if the value of the "fieldN" field equals "valueN", then Form Processor Pro counts this field. If value is not specified, Form Processor Pro checks if field is empty. If it is filled, Form Processor Pro counts this field.
Example:
Let's say we have filled a form with the the following fields ("" - empty values):
Result:
You can count different combinations of these fields using the count_fields feature
Example 1:
Count how many names were entered:
This will set the variable {#name_count#} to 5
Example 2:
Count how many cities are filled:
This will set the variable {#city_count#} to 6
Example 3:
Count how many people are aged 18
This will set the variable {#count_age18#} to 3
Example 4:
Count how many people are aged 18 and filled their name:
This will set the variable {#count_name18#} to 2
Example 5:
Count how many people are from washington, are 21 and filled their name:
This will set the variable {#count_name_washington21#} to 1
As you can see, each example contains the same regular expression structure. Let's see how it works:
"/" and "/" are used like brackets to set where the regular expression starts and ends.
"name" - is a part of the field name that remains unchanged. In our example, there are three of them: "name" , "age", "city".
(.{0,3}) - is an expression that captures any string with length up to 3. It allows to capture such fields as "name1", "name6", "nameaaa", "nametjz", "name134" in our example, but ignore such fields as "name_of_person", name9238", "namefrjhgh". You can set any other number instead of "3", but note that larger numbers slow down the script.
i - means that fields names will be case insensitive, so Form Processor Pro will not differentiate between "nAme3", "Name3" and "name3" field names.