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

How require ALL req fields to be completed before show submit button?

Jesterm
Registered: Apr 9 2010
Posts: 9
Answered

Hi all,

I have created a form and would like the submit button (button I created and configured to send entire PDF by email) only to appear after ALL required fields have been filled in. I have also configured button to reset form after submitting as it may be used on public computers. The problem is if a person misses one of the required fields and hits the submit button, he is informed there are more required fields but then the form is reset.

any ideas?

Thanks
Jester

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
You need to run some script to test if all of the required fields have been filed in with a non-default value.

Beware that the Acrobat JavaScirpt does not return a status value for the 'submitForm' for you to check.

George Kaiser

Jesterm
Registered: Apr 9 2010
Posts: 9
Thank you gkaiseril,

I was afraid of that. I'm new to Acroforms and don't know javascript.

Thanks for the quick reply.

Jesse
Jesterm
Registered: Apr 9 2010
Posts: 9
I have done my best to learn a bit of code but need some help. I am trying to ensure all required fields are complete before submitting PDF by email. Can anyone see what I'm doing wrong? Thanks in advance.

var RequiredFields = new Array(6);
RequiredFields[0] = "reason";
RequiredFields[1] = "first_name";
RequiredFields[2] = "last";
RequiredFields[3] = "birthday";
RequiredFields[4] = "initials";
RequiredFields[5] = "agree";


var AlertMsg = new Array(6);
AlertMsg[0] = "Please complete the reason why you came to our office.";
AlertMsg[1] = "Please enter your first name.";
AlertMsg[2] = "Please enter your last name";
AlertMsg[3] = "Please enter your birthday.";
AlertMsg[4] = "Please enter your initials.";
AlertMsg[5] = "Please complete agreement section.";

var bSuccess=True
var emptyTest = /^\s*$/;
var fieldCount = RequiredFields.length
var fld = 0;

for (var i=0; i < fieldCount; i++)
{
fld = this.getField(RequiredFields[i]);
if( emptyTest.test(fld.value) ) // if required field is empty
{
bSuccess=false;
app.alert(alertMsg[i]);
fld.setFocus();
break;
}}
if(bSuccess)

var cToAddr = "email1 [at] email [dot] com";var cCCAddr = "email2 [at] email [dot] com";var cSubLine = "Registration form returned from "
+ this.getField("first_name").value + " "
+ this.getField("last").value;

this.mailDoc ({bUI: true, cTo: cToAddr, cCc: cCCAddr,
cSubject: cSubLine,});








George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You had a number of typos and I fixed a few other things. It may not work exactly as you intended, but it should work. Some of the changes I made were to suit my programming style and simplify a bit.


(function () {

var RequiredFields = ["reason", "first_name", "last", "birthday", "initials", "agree"];

var AlertMsg = [
"Please complete the reason why you came to our office.",
"Please enter your first name.",
"Please enter your last name",
"Please enter your birthday.",
"Please enter your initials.",
"Please complete agreement section."
];

var bSuccess = true;
var fieldCount = RequiredFields.length;
var fld;

for (var i = 0; i < fieldCount; i++) {fld = getField(RequiredFields[i]);

if (!fld.valueAsString) { // if required field is empty
bSuccess = false;
app.alert(AlertMsg[i]);
}
}

if (bSuccess) {

var cToAddr = "email1 [at] email [dot] com";
var cCCAddr = "email2 [at] email [dot] com";
var cSubLine = "Registration form returned from " + getField("first_name").value + " " + getField("last").value;
mailDoc ({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine,});

} else {

// Set focus to last empty field detected
fld.setFocus();
}

})();
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Unfortunately, this darn new forum software mangled that a bit, but hopefully you'll get the idea.
Jesterm
Registered: Apr 9 2010
Posts: 9
You rock George! Thanks, it works like a charm. I really appreciate it.


George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Actually, the setFocus part is wrong, as it doesn't go to the last empty field detected, but the last field tested. But you should be able to fix that.