Tutorials, tools, scripts and samples for scripting Acrobat and PDFTutorials, tools, scripts and samples for scripting Acrobat and PDF
HomeVideo TutorialsCopy-n-Paste ScriptsDownload LibraryFree ContentSearchMEMBERS AREA


 About this Site
About Us
Contact Us
Privacy Policy
Refund Policy
Site Video Tour
Terms of Use
Testimonials
 DEPARTMENTS
Articles
Video Tutorials
Automating Acrobat
Copy-n-Paste Scripts
Download Library
Free Content
Free Videos
 RESOURCES

Let me know when new content is available.

Home | Form Data Validation
 

Form Data Validation

Thom Parker

Form data validation comes in a couple different forms. Data can be validated at the field level when it is entered by the user, and it can be validated at the form level (i.e. all fields) when the form is submitted or printed. These different types of validation have different, complimentary purposes and for a complete form design it's a good practice to use a combination of the two methods.

Field Level Validation

The purpose of Field Level Validation is to verify that the input to a single field is entered correctly. For example, for an email field, the job of the validation script is to make sure the entered text matches the standard email format, i.e., two sets of strings separated by an "@" symbol. The most common way to implement a text pattern test like this is to use a Regular Expression. In fact, this example is fairly typical. Most of the time validation scripts are used to match input text against a pattern using a regular expression. But of course, this is not the only way to implement a validation script and it's not the only thing a validation script can be used for.

After testing the input data the Validate Script can completely reject an entered value, alert the user to a problem, and even modify the entered value before it is committed to the field. It can also be used creatively for non-validation purposes. So there is quite a bit of flexibility in how this event can be used.

Field Validation is performed by a custom Validation Script on the field itself. The Validation Script is entered in the Validate tab of the properties dialog for the text field, as shown in the image above. The Validate event is received by all of the different field types, but the text field and combobox are the only ones that have a user interface for entering a script. A Validate Script can only be entered into other field types with JavaScript.

Find out more about the Validate Event from the Articles at the bottom of the page, and from these videos:


Form Level Validation

Form level validation is used to ensure all the required form data is filled in, and/or to make sure that any data dependencies between fields are met before the form is submitted. Usually, this type of validation uses a much simpler data test than field level validation because it's assumed that field level validation guarantees any entered data is correct.

If you've filled out a form on a web page then you've seen this in action. On a web page, the required fields are usually indicated with a red "*". And if you don't fill one out, then on submit you'll get the same page back with a warning message at the top telling you to fill out the marked fields. In Acrobat, it's a little different. You can certainly do this check on a submit, but since PDF documents are standalone, i.e., they can be returned by printing or by file transfer, you may also want to do form level validation when the form is saved or printed.

Acrobat has a kind of built-in Form Level Validation. The PDF form fields have a required property. Any field that is marked with "required" must be filled in before Acrobat will allow the PDF to be submitted. On a failed submit, Acrobat will display a popup message and highlight all required fields, whether they are filled in or not. Unfortunately, Acrobat doesn't do any checking when the document is printed, saved, or emailed using JavaScript. This built-in validation also doesn't work for check boxes, and it only checks to make sure a field is filled out. If you need to do something outside of these limitations, for example making sure an "I Agree" check box is checked, then you'll need to write your own Form Level Validation script.

The "required" fields property can be both examined and manipulated by JavaScript, so the required fields can be changed dynamically. This is important for handling optional sections of a form. For example, many forms have a section to be filled out by a parent or guardian if the main user is under age. In this case a script on a check box could be used to set all the fields in this part of the form to required when checked. Even if the form does not use the built-in form level validation, these required values can be used by a custom script to determine which fields it will test.

There is a great deal of flexibility to how form level validation is used. To find out more see the articles listed below.


Acrobat XI Forms Training
Thom Parker, Forms
This video tutorial series covers everything you need to know about how to create forms and form workflow processes with Acrobat XI. It starts out with a set of no holds barred videos that intr . . . keep reading
Field Validation Script Basics
Validate, Event
Eight examples that demonstrate the basics of using the Validation Event Script for a field on an AcroForm PDF. Six standard examples for Text Fields. All use Regular Expressions to analyze field data. Two Alternate Use examples, one of which uses a ComboBox Field. . . . keep reading
Form Level Validation - Strategies
Thom Parker
Form level validation is used to ensure all the required form data is filled in, and/or to make sure any data dependencies between fields are met before the form is submitted, saved, printed, or emailed. . . . keep reading
Form Level Validation Scripts
Thom Parker
It would be impossible to provide examples for all the variations on validation. So, the scripts below are categorized into the different parts of validation . . . keep reading