Online Chat
 Call Us: 
1-877-744-1221
Browse Submit a Ticket
 
Advanced Search
Tools
Rss Categories

Fields Counter

Author: Eileen Wilde Reference Number: AA-00172 Views: 3605 Last Updated: 10/20/2009 09:39 AM 0 Rating/ Voters

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:

count_fields = output_field; regular_expression; field1[= value1][; field2 [=value2][; ... ]]

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):

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 the count_fields feature

Example 1:

Count how many names were entered:

count_fields = name_count; /name(.{0,3})/i

This will set the variable {#name_count#} to 5

Example 2:

Count how many cities are filled:

count_fields = city_count; /city(.{0,3})/i

This will set the 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 the 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 the 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 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:

/name(.{0,3})/i

"/" 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.