Data validation (data validation: The process of testing the accuracy of data; a set of rules you can apply to a control to specify the type and range of data that users can enter.) can be used to display error alerts when users enter incorrect values into a form. Rather than checking for errors after
a form is completed,
data
validation verifies values as
the
form is being filled out.
Working with data validation when filling out a
form
Microsoft Office InfoPath 2003 automatically checks the data you
type into a form and displays an error alert if the value does not match the condition specified by the data validation rule. If a value you enter does not match the specified condition, an error
alert provides you with immediate feedback.
Error alerts can be either dialog box alerts (dialog box alert: A data validation alert that opens a dialog box with a custom error message when invalid data is entered into a control.) or inline alerts (inline alert: A data validation alert that marks controls that contain invalid data with a dashed red border. Users can right-click controls to display custom error messages.). You can correct errors immediately, or you can use the commands on the Tools menu to navigate through and correct all the errors in a form at once. Uncorrected errors are marked with a dashed red border. Required entries are marked with a red asterisk or, for some types of controls, a dashed red border. To see details about the error, you can right-click the control.
If you save a form without fixing the errors, you will be reminded about the errors with a dialog box alert. You can save forms with validation errors, but you cannot submit them.
Working with data validation when designing a
form
Data validation is always associated with a specific control (control: A graphical user interface object, such as a text box, check box, scroll bar, or command button, that lets users control the program. You use controls to display data or choices, perform an action, or make the user interface easier to read.) and
occurs when
a user fills out a form. Note that InfoPath verifies a condition by checking
the value of the field (field: An element or attribute in the data source that can contain data. If the field is an element, it can contain attribute fields. Fields store the data that is entered into controls.) that is bound (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) to the control, not
the control itself.
Types of data validation
InfoPath supports several types of data validation,
each of which can be used separately or in combination:
- Required fields Requires users to enter a
value into a control.
- Data-type validation Requires users to
enter a particular type of data, such as whole numbers or dates, into a
control.
- Range checking Ensures that the value
entered into a control is within the specified range. For example, range checking can limit an expense
item to less than $500.
- Dynamic comparisons Compares values in
different controls. For example, dynamic comparisons can require a shipping date to occur
after an order date.
- Data patterns Requires users to type values in a specific pattern, such as a phone number.
- Code-based validation Uses custom code to
perform advanced validation on a control.
Types of error alerts
When you add data validation to a control, you can specify one of two types of error alerts to display to users:
- Inline alert Marks controls that contain
invalid data with a dashed
red border. The user can right-click
the control to display a standard or custom error message.
- Dialog box alert Opens a dialog box with
a custom error message when invalid data is entered into a control. If the user does not fix the error immediately the control is marked with an inline alert.
Schema-based validation
If your form is based on a pre-existing
XML Schema (XML Schema: A formal specification, written in XML, that defines the structure of an XML document, including element names and rich data types, which elements can appear in combination, and which attributes are available for each element.), InfoPath automatically
validates data entries based on the schema constraints. In some cases, these
constraints are similar to or the same as the standard data validation available
in InfoPath; data-type validation, for example, is a kind of schema-based
validation. In other cases, the pre-existing schema may contain more
extensive validation, including advanced data types. Error alerts for schema-based validation appear as standard inline alerts.
To test a data validation constraint, including the conditions and
error alerts, preview your form and enter valid and
invalid data into the control you want to test. Error alerts will appear in the preview
exactly as they appear to your users.
Note The information in this topic may not apply if you are working with a form designed using Microsoft Office InfoPath 2003 without the service pack installed.