These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Form Validation on Submit button! Help!!

acrobatforms
Registered: Feb 10 2009
Posts: 3

Hi everyone,

I am new to using Javascripts in Acrobat Professional. I created an application form (3 pages) and applied "Print form" & "Submit form" buttons at the end of the document.

There are many fields in the form that are mandatory for the applicant to fill in.
I am looking for a way to validate and maker sure all the fields are filled before submitting the form via email.

Any help is appreciated, thanks in advance for your time.

Cal.

My Product Information:
Acrobat Standard 9.0, Windows
maxwyss
Online
Registered: Jul 25 2006
Posts: 255
The procedure is relatively straightforward. You loop through the fields of your form, find out whether it is one of the mandatory ones, and if so, you compare its value with its default value. You may create a counter which you set to 0 to start with, and increment every time, the field's value is equal to the default value. After you have processed all the fields, you evaluate the counter and proceed.

There is actually a field property "required". Unfortunately, it is of rather limited use, because it is only the Submit action which honors it. You may use it in order to determine whch field should be evaluated. You may also use any other field property (in many of the projects I provided the engine, we evaluate the field's border color.

In pseudo-code the procedure would look somewhat like this:

var cnt = 0 // that's the counter
for (var fi = 0 ; fi < this.numFields ; fi++) {
var fifi = this.getNthFieldName(fi) ;
if (fifi.includeproperty == includepropertyvalue) {
if (fifi.value == fifi.defaultValue) {
cnt++ ;
}
}
}
if (cnt > 0) {
// send failure message
} else {
// proceed with submit or print
}

And that would be your evaluation routine.

Note that in the case of printing, you would have to create a big "Print Me" button, and instruct the user to only use this button, because there is no known way in JavaScript to stop a print command issued via keyboard shortcut, menu action or toolbutton.

Hope this can help.

Max.