Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
1. This is a code I wrote, but it's an older version of it.
Replace this part:
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off"))
With:
if (f.valueAsString==f.defaultValue)
2. That part of the code seems fine. Is there an error messege when you try to use it?
Try running just the last line (without the "else" part) from the Console. Does that work?
Copy link to clipboard
Copied
1. This is a code I wrote, but it's an older version of it.
Replace this part:
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off"))
With:
if (f.valueAsString==f.defaultValue)
2. That part of the code seems fine. Is there an error messege when you try to use it?
Try running just the last line (without the "else" part) from the Console. Does that work?
Copy link to clipboard
Copied
In the first part, I subbed your new line of code for the old one, and now it alerts for required radio buttons that are left blank. Yay!
For the second part, it doesn't give any sort of alert. If the requireds are filled out, it doesn't attach to an email, it does absolutely nothing...like there isn't a button at all. I took out the "else", as you suggested, and it didn't make any difference. (Was that what you wanted me to do? That's how I understood your directive. My apologies if I got it wrong!)
I SO appreciate your time and advice!!
Copy link to clipboard
Copied
Press Ctrl+J and see if there are any error messages in the window that opens.
Copy link to clipboard
Copied
It's not showing any....a snip is below
...a snip is below.
Copy link to clipboard
Copied
Can you share the actual file with us? You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.
Copy link to clipboard
Copied
Done!!
Copy link to clipboard
Copied
1. You need to put back the "else" keyword before the last line, or it will submit the form no matter what.
2. Click the button and then check the console again. You'll see an error message there.
Copy link to clipboard
Copied
ahhhhhh!!! I see what I did. When I renamed those two fields (so they'd be purdy in the error message) I didn't think to rename them in the javascript. I corrected the errors, returned "else", and now it works perfectly.
Thank you SOOO much for your help. I really appreciate it. By chance, do you have a Ko-fi or anything like that???
Copy link to clipboard
Copied
Copy link to clipboard
Copied
(gentle reminder to others who may view this thread...if you're able, send love to those who help you.)

