TX Text Control provides a unique way to create documents with fillable form elements such as form text boxes, checkbox fields, and drop-down elements. These forms can be created like mail merge templates and dynamically populated with values from form data sources. Using conditional statements, it is possible to add dependencies between fields based on logical operators. This allows you to add a complete workflow to forms by adding dependencies between form fields.
You can use the Document Viewer to deploy document forms with form field elements that contain conditional instructions for users to complete.
Let's take a look at the simple payment form in the screenshot below:
Creating this form layout is really easy using the word processing interface of the TX Text Control Document Editor. All you need to do is to create a document with a table structure and form fields that can be added using the Form Fields ribbon tab. This article does not describe that part, but the smart logic behind the form fields.
Download the sample form and load it into the Document Editor or the shipped Windows application TX Text Control Words.
In order to add conditional instructions to the form fields, you have to enable the validation by clicking the button Enable Form Validation in the Form Validation ribbon group.
This form contains 11 conditional instructions to cover the logic and validation of a credit card. Open the instruction named Payment_Card_Number_GetValue by selecting it and clicking Edit....
This instruction validates the payment_number form field by matching a regular expression for each payment method. For example: If the VISA checkbox is checked and the number matches the conditions that it starts with a 4 and is 12 digits long, the field is valid. Here are the characteristics of the credit cards used:
- All VISA card numbers start with a 4.
- New cards have 16 digits. Old cards have 13.
- MasterCard numbers either start with the numbers 51 through 55 or with the numbers 2221 through 2720.
- All cards have 16 digits.
- All AMEX cards start with 34 or 37
- All cards have 15 digits.
Enable Checkboxes Automatically
To improve the user experience, the checkbox can be set automatically by matching the credit card number. This can be seen in the instruction Payment_Card_Number_VISA_SetValue for matching VISA credit card numbers:
If the credit number is recognized as a VISA card, the appropriate checkbox is checked and others are unchecked. When you load a document with form fields and conditional instructions into the Document Viewer, the form fields are automatically enabled:
The other conditional instructions are simpler and check for non-empty fields. The only more complex field is CCV, as the validity of this field again depends on the credit card selected. 3 digits for VISA and Mastercard and 4 digits for AMEX.
If all fields are filled in correctly, the forms.validate ╰ TX Text Control .NET Server for ASP.NET
╰ TXDocumentViewer Object
╰ forms.validate Method
You can download this sample form here for your own testing.