Please enable JavaScript to view this site.

iService Forms User Guide

Navigation: Form Commands > $IF

$IF -fieldregex

Scroll Prev Top Next More

The $If -fieldregex parameter is used to evaluate the status of fields within an iService form using regular expression. When the form loads, the enclosed text is either inserted or not  depending upon whether the value in the named field is a match for the specified regular expression.  This parameter is useful within forms that tend to be reloaded for various reasons, whether because of an error or user input. The expression checking is limited to comparing form field contents to a hard-coded regular expression.

 

Example 1: Checking values of a submitted form.

If custom HTML is used and a form is submitted with an error because of a missing field, -fieldregex can be used to preserve the values originally entered into a form. This is illustrated below.

<label>I have a question about:</label>

<div>$input -id'requesttype' -required -customhtml$</div>

 <select name="requesttype">

   <option value="">Please Choose One</option>

   <option $if -fieldregex'requesttype'='Product'$selected$endif$ value="Product">Products</option>

   <option $if -fieldregex'requesttype'='Service'$selected$endif$ value="Service">Services</option>

   <option $if -fieldregex'requesttype'='Other'$selected$endif$ value="Other">Other</option>    

 </select>

</div>

 

In the example above, the form has an input named requesttype. The -fieldregex parameter determines whether the option was selected when the form was submitted, and sets the value when the page is reloaded by setting the option to "selected" if true. In this example, the $else$ command is not used.

 

Example 2: Determining whether a topic was selected in a Find Answers form.

Find Answers FAQ forms allow the user to search within a topic, or across all topics. The $IF -fieldregex below is used to determine whether a topic was selected when the search was submitted and return the proper results.

 

$if -fieldregex'topicID'='$^'$

    If the topicID is blank, then search on the entire topic tree.

$else$

    If the topicID is not blank, then limit to search to the specified topic.

$endif$