Validating Form DataLast Updated: 12/03/2015 Introduced in Verision: 2.0 |
One of the most common requirements of an application is to validate form inputs before accepting them. By assigning rules to forms within a flow, the system can validate form data before submission, preventing users from entering invalid information in an application. When the rule returns False, the validation will be enforced.
For example, data entered in an email address field should be in the proper format. A validation rule assigned to the email address field can check the format. If the format is invalid, an error displays when the user attempts to submit the form, and the error must be corrected before the form can be submitted.
Set validation rules for a form in the Form Designer, in the Properties panel, in the Custom Validation Rules section.
Example
Our example flow will illustrate how form data can be validated according to custom rules.
In our example, we will set the Email ID field of the form component to only accept valid email addresses. Start Date will only accept today’s date or a date in the future. End Date will only accept dates occurring after today. Our example assumes that our form Custom Validation Form has already been created, and is ready to be configured. It also assumes that the rules that will validate the fields have also been created.
Many commonly used validation rules can be found in Root > System > Shared Designer Elements > System Defaults > Default Form Validation Rules.
To begin, navigate to a project folder and click the Create Flow button. To add a project folder, select the Actions button, then select Add > Designer Project and fill in the name and select OK.
Name the flow and click OK. The form will open. From the Flow Designer’s startup window, expand the Flows, Rules, Forms and Reports > Forms [Interaction] > [Current Folder] category, select the Custom Validation Form component and click Add to add it to the workspace.
Connect the form component to the End Step.
To assign validation rules to the form, select it and click the Edit Form link at the top of the Properties panel.
To assign rules to a form, expand the Explorer panel and select Surface.
In the Properties panel, locate the Rules field under the Custom Validation Rules section. Click Add to choose a custom rule to add to the form.
To create the rule, enter a name in the RuleName field. In the Rule drop-down list, navigate to the folder containing the rule and select it. The rule must return False in order for validation to be applied.
Many commonly used validation rules can be found in Root > System > Shared Designer Elements > System Defaults > Default Form Validation Rules.
In the ValidationBreakText box, enter the message that will be displayed if the rule is broken. In the ApplyToControls list, select the checkbox next to each form control that the rule should be applied to.
In the Inputs box, select the input and click Edit.
In the Edit object pop-up, you can further specify information about the input that the validation rule will check.
To specify that the input will come from a form, from the InputType drop-down list select Form.
To indicate the field on the form that the validation rule should check, select it from the FormDataName drop-down list.
Click Save to save the changes and close this pop-up, then click Save on the Edit object pop-up to save the validation rule.
You can follow this process to add two more validation rules.
Add a validation rule to check that the Start Date is the current date or a date in the future . . .
. . . and should be run against data entered in the Start Date field on the form.
Finally, you can add a validation rule to check that the End Date follows the Start Date . . .
. . . and should be run against data entered in the End Date field on the form.
If you have completed configuring the form, save the form and close the Form Designer.
The flow is also finished, save the flow and close the Flow Designer.
To see the flow in action, click the Action link in the new flow’s thumbnail and select Run > Run Flow.
Enter an email address in an invalid format and click OK. An exclamation mark displays next to the field and the OK button, and a message appears with the text we entered in the ValidationBreakText box.
When you enter invalid dates and click OK, the validation rules check the data, and the error message displays.