Splicing together two strings of javascript + slightly changing one
Hi all,
I’m running Acrobat Pro DC, and revising a referral form that’s a fillable PDF. Originally the form included a bit of javascript so that when the submit button was clicked, the resulting email contained “referral” followed by the client name. (My experience with javascript consists of the research I did to find that code.) Here’s what I used—with the email address x’d out:
---------
this.mailDoc({
bUI: false,
cTo: "xxxx@xxxx",
cSubject: "Referral:" + " " + this.getField("last name").value + ", " + this.getField("first name").value,
});
---------
It worked great. Now, a year and a half later, I’m tasked with revising the referral. One of the things I’m adding is required text boxes and radio buttons. Now I need the submit button to:
- Check for blank required fields
- Prompt the end-user to fix any that are found
- Once they are fixed, attach itself to an email like it did above-with the client name in subject line.
Some heavy research uncovered a 2013 thread in this forum with a similar question, and from it I got this from Try67’s answer for the required portion:
---------
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
---------
Further in the thread, they said that in order to include a submit function, add this at the end:
---------
else this.mailDoc({cTo: "me@server.com", cSubject: "Subject line of the email", cMsg: "Message body of the email"});
---------
I did it, but subbed in the old specifics for subject and got this:
---------
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
else this.mailDoc({cTo: "AdultProbationJobs@sc.pima.gov", cSubject: "Referral:" + " " + this.getField("last name").value + ", " + this.getField("first name").value, cMsg: "Message body of the email"});
---------
...but it won't work right! Here's what I would love help with:
- I can’t figure out how to get the alert to pop up for required radio buttons that are left blank, and
- The submit portion doesn’t work.
What am I doing wrong? I very much appreciate any help you can give!
