Fields Counter |
![]() ![]() ![]() |
Fields Counter helps you to count how many fields from a field set satisfy certain conditions. This may be used in surveys and with repeating field set. Syntax: count_fields output_field; regular_expression; field1[= value1][; field2 [=value2][; ... ]] output_field - field where result will be put. You can use it in any page or template as any other field: {#output_field#} regular_expression - count fields fit this expression. See below for detailed explanation. fieldN = valueN - field conditions, if value of "fieldN" field equals "valueN", then Form Processor Pro counts this field. If value is not specified, Form Processor Pro checks if field is not empty. If was filled, Form Processor Pro counts this field. Example: Let's say we have filled form with following fields ("" - empty values):
name1 = John age1 = 18 city1 = New York
name2 = Kim age2 = 18 city2 = Washington
name3 = John age3 = 21 city3 = Washington
name4= Mary age4 = 21 city4 = Sydney
name5 = Adolph age5 = 70 city5 = Berlin
name6 = "" age6 = 18 city6 = Paris Result: You can count different combinations of these fields using count_fields feature
Example 1:
Count how many names were entered:
count_fields name_count; /name(.{0,3})/i
This will set variable {#name_count#} to 5
Example 2:
Count how many cities are filled:
count_fields city_count; /city(.{0,3})/i
This will set variable {#city_count#} to 6
Example 3:
Count how many people are aged 18
count_fields count_age18; /age(.{0,3})/i = 18
This will set variable {#count_age18#} to 3
Example 4:
Count how many people are aged 18 and filled their name:
count_fields count_name18; /name(.{0,3})/i; age = 18
This will set variable {#count_name18#} to 2
Example 5:
Count how many people are from washington, are 21 and filled their name:
count_fields count_name_washington21; /name(.{0,3})/i; age = 21; city = Washington
This will set variable {#count_name_washington21#} to 1
As you can see, each example contains the same regular expression structure. Let's see how it works:
/name(.{0,3})/i
"/" and "/" are used like brackets to set where regular expression starts and ends. "name" - is a part of 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 would be insensitive to the register, so Form Processor Pro will not make difference between "nAme3", "Name3" and "name3" field names. |