Validating data in InfoPath forms

When it comes to forms, it is usually important to ensure that the correct type of information is collected in each form field. In InfoPath, fields can be configured to be required or to only allow certain types of information, such as numbers. In addition, we can use validation rules to ensure the data entered meets the specified requirements, such as being a number greater than the number entered into the previous field.

In this recipe, we will create a required field that only allows whole numbers between 10 and 20.

How to do it...

Follow these steps to create a required field with a validation rule:

  1. Create a new form template or open an existing one in Microsoft InfoPath Designer 2013.
  2. Add a Text Box control to the form.
  3. Navigate to CONTROL TOOLS | PROPERTIES and with the Text Box control selected, change Data Type to Whole Number (Integer) as shown in the following screenshot:
    How to do it...
  4. Select Field Properties from the Properties section of the ribbon.
  5. Select the Cannot be blank option as shown in the following screenshot:
    How to do it...
  6. Click on OK.
  7. If the Rules pane is not currently displayed, select Manage Rules from the ribbon to display it.
  8. Select Validation from the New menu in the Rules pane.
  9. Provide a name for the rule, such as Between 10 and 20.
  10. Under Condition, select the None link.
  11. Set the conditions to check if the value of the textbox is less than 10 or greater than 20 as shown in the following screenshot:
    How to do it...
  12. Click on OK.
  13. Enter a ScreenTip to be displayed to the user, such as Value Must be Between 10 and 20.
  14. Using the Preview option, preview the form template to observe the behavior of the field when entering non-numeric values, numbers greater than 20 or less than 10, and numbers between 10 and 20.

How it works...

When data in a field does not meet the requirements specified, we can prevent the form from being submitted. This allows the user to correct the information before submitting it again. These requirements are enforced using validation rules in the InfoPath engine. The Cannot be blank option makes the field required. The Condition for a validation rule may be quite complex. Custom formulas can be used, the conditions can vary depending upon the values of other fields, and so on. In this recipe, we simply ensured that our field is not empty and that it has a value between 10 and 20.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.87.161