[an error occurred while processing this directive]

Detailed Documentation on Conditional (if/else/endif) Processing

This page is part of the WebCom Forms Processor Guide. This page describes in detail how to use if/else/endif in your form configuration file. This page describes in detail the syntax and rules for using if/else/endif. There is also an introductory page on if/else/endif.

The structure of an if/else/endif construct in the configuration file is as follows:

if (condition)

(statements)

else

(statements)

endif

The following operators are available for testing values (for use in the condition expression in the if statement):

Numeric test    String test     Meaning
    ==              eq          Equal to
    !=              ne          Not equal to
    >               gt          Greater than
    >=              ge          Greater than or equal to
    <               lt          Less than
    <=              le          Less than or equal to
    !               !           (Boolean) Not (!TRUE = FALSE/!FALSE=TRUE)
                                if (! ($order_amt >= 100)) is the same as
                                if ($order_amt < 100)

Note the distinction between testing string (alphabetical) values, and testing numeric values. (e.g. "50" comes after (is greater than) "456" alphabetically, but "50" is less than "456" numerically).

You can do complex comparisons using && (and) and || (or). && is evaluated before ||, but parenthesis can be used to override the order of operation.

Example:

if ($salary>30000 && $no_cars>3 || $salary > 60000)
format screen
Congratulations!  You qualify for a super-gold card with no annual fee!
.
endif

You can use and exclamation point (!) for "not":

if (!($salary>30000 && $no_cars>3 || $salary > 60000))
format screen
Congratulations!  You qualify for our layaway purchase plan!
.
endif

If you know how to use UNIX regular expressions, you can also check for pattern matches:

    =~   /pattern/[i]      Matches pattern [i = case insensitive]
    !~  /pattern/[i]       Does not match pattern

For example:

if ($phone_no !~ /\(\d\d\d\) \d\d\d-\d\d\d\d\)/)
format screen
<LI>Please enter your phone number in this format: (nnn) nnn-nnnn
.
endif

Regular expression patterns must be compatible with PERL regular expressions. Refer to the PERL Home Page for additional resources for learning about about PERL regular expressions (Programming Perl [Nutshell Handbook], Larry Wall [Editor], et al; O'Reilly & Associates; ISBN: 1565921496 is probably the best resource).

Note that you can create new parameters and set their values (see the Forms Processor parameter introduction page). You can use conditional processing to set various parameters you define and then take certain actions based on the values of your parameters. This helps alleviate the limitation of no nested ifs, and can be used to create very intelligent forms.

PLEASE NOTE: When setting parameter values to literal values, quotes are optional ($email=me@webcom.com). However: quotes are required for literal values in conditional tests! (e.g., if ($email eq "me@webcom.com") ). If this is confusing to you, just remember this rule: always surround literal string values with double quotes, and you'll be fine.

An example of using a custom parameter with if/else/endif can be seen on the if/else/endif introductory page.

As well as comparing field values and literal values with comparison operators and patterns, you can compare with the return value of the following functions:

For more info on the use of these commands you can see our Advanced Commands section.

[an error occurred while processing this directive]