Requiring and validating data

Last updated on November 22, 2024

Help ensure submitted forms are complete and correct using validation.

On this page:

An overview of validation

Validation is set up for each control through the control settings.

Validation can check that:

  • Required fields are completed (recommended)
  • Data entered matches a particular type (set by the control)
  • Data entered falls within specified constaints (optional)
  • Data entered conforms to a specified formula (optional)

Validation only works on controls that are visible to the user.

For a detailed explanation of validation see:

Using formulas for validation

Since alert messages are placed next to the formula space it's possible to think, "if this is true then display the error." It's actually the opposite.

Formulas must resolve as 'true' to PASS validation and NOT display the messge.

This is consistent with the way formulas are used throughout Orbeon.

The user experience

In the form displayed to the user:

  • Required fields have no special markings or decoration
  • Optional fields have the word " (optional)" appended to the label

It's designed this way because:

  • It's a better experience for those that use screen readers
  • Government shouldn't ask for information that's not required
    • Exceptions are things like a second address line
    • Conditional questions can be concealed with visibility until needed

When a user skips a required field or enters something incorrectly:

  • The alert message is displayed under the field
  • A "messages" section is displayed at the bottom of the form that:
    • Displays the field label where the issue occured
    • Displays the alert message
    • Links to the location in the form the issue occured

Users will not be able to submit their form until all messages are cleared.

Improving the user experience

The default alert message is, "Missing or incorrect value".

Consider providing a message that is more specific to help the user correct the problem like, "Password must be at least 8 characters."

This information may have been provided in the hint text, but some users may not have read it clearly or paid attention to it, and the hint will be hidden by the alert.

To change an alert message:

  1. Uncheck the box to the right of the message
  2. Replace the Alert Message text

Making fields required

It's recommended that all fields on a form, with a few exceptions, are marked as required.

To make a field required:

  • Select "Yes", or
  • Select "Formula" and enter one

Remember that:

  • Only visible fields are validated
  • You can use visibility to hide a required field that's only required in certain circumstances

Data type validations (information)

Data type validations ensure that data entered into a field is a certain type, such as boolean, email address, integer, or others. The data type is preset based on the type of control it is and won't need to be changed in nearly all circumstances, but it can be if you need it.

Using common constraints

Common constraints can vary depending on the type of control and data type selected. They provide a shortcut to defining some sort of limitation to the data entered, saving you the task of defining that limitation with a formula. For example, the common constraints of a text field are the minimum and maximum length (number of characters).

Validating with formulas

You can also use a formula to determine if data entered is valid. Common uses are to ensure that:

  • Data falls within a range of digits, such as between 1 and 10
  • Data matches a particular pattern, such as the A1A1A1 pattern of the postal code
  • Another value meets a certain criteria

Example of a cross-reference validation

Let's say that your form includes a set of values for childcare spaces separated by age range. Each control has an Initial Value of zero, which is valid for any given range. However, you want the value of at least one of these ranges to be one or higher. In other words, the total number of spaces must be at least one. You can set up a hidden or non-visible field called facilitySeats that sums up the total of seats across the ranges.

  • The facilitySeats control has an Initial Value of '0' and uses the sum() function to add up the values of the age ranges
  • Each of the age range controls is given the validation formula of $facilitySeats >=1
  • So long as the total number of spaces across all age ranges is zero, the value for that age range is invalid
  • Once at least one of the age ranges has a value of one or more, $facilitySeats will have a total value of one or more, making all age ranges valid