Validate the User's Input

When the user clicks a button that is configured to cause validation, validation is performed for each element in the form that has validation configured. There are two ways to configure validation for a form element:

In the following screen capture, the user has submitted the form without selecting a state. Because the state is configured to be required, the form will not close until the user enters the state.

Example of a validation message in a form

Example - Subworkflow for a Validate Event

This example illustrates one way to validate an email address in a validate subworkflow. The subworkflow looks like this:

Flowchart for a subworkflow that validates an email address

The validate subworkflow uses a regular expression to compare the user's input to the pattern for a valid email address (), and then branches based on whether the input matches the pattern or not (). If it doesn't match (), the subworkflow sets an error on the input element and the error message displays in red text above the element. If the input does match the pattern (), the subworkflow clears any error that was previously set on the input element.

Error message on the Email Address text box

To configure a validate subworkflow that tests the validity of an email address:

  1. Add a text box with a validate event:

    1. Edit a Display Form activity.

    2. Add a text box to the form and change its title to Email Address.

    3. Select the text box to show the Properties panel, and then click the arrow beside Events to show the events.

    4. Click Add beside the validate event.

      A blank Event subworkflow opens.

  2. Test whether the input is valid:

    1. Drag a Regular Expression Matches activity to the design surface and connect it to the Event block.

    2. In the Text input, type an equals sign (=) followed by a reference to the user's input, for example, $form1.state.textBox1.value.

    3. In the Pattern input, type or paste the regular expression that defines the pattern for the email address, for example:

      ^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)

  3. Branch based on whether the input is valid:

    1. Drag an If activity to the design surface and connect it to the Regular Expression Matches activity.

    2. Set the Condition input to the result of the Regular Expression Matches activity, for example, =$regexMatches1.result.

  4. Invalid input:

    1. Drag a Set Form Element Error activity to the design surface and connect it to the If activity's False branch.

    2. Set the Element ID input to the Element ID of the text box.

    3. Set the Error input to the error message that you want to display above the text box, for example, Email address is invalid.

  5. Valid input:

    1. Drag a Clear Form Element Error activity to the design surface and connect it to the If activity's True branch.

      Whenever you use a Set Form Element Error activity, make sure you also use a Clear Form Element Error activity to clear the error. Otherwise the form may get stuck in an invalid state.

    2. Set the Element ID input to the Element ID of the text box.

  6. Click Display Form in the breadcrumbs to return to the form preview.

    You can re-open the subworkflow from the text box's Actions menu or by clicking Edit in the Properties panel.

© 2021 VertiGIS North America Ltd. All Rights Reserved.

Documentation Version 5.20