Copy link to clipboard
Copied
Trying to get a form with required fields to work.
I have two buttons - one for email to XXX address, the other for saveAs.
The following code works perfectly for emailing, but I cannot get it to work using saveAs, doc.saveAs();
app.execMenuItem("Save");
The testing of the required fields works for both, but once the test is satisfied the saveAS does nothing.
var c = 0;
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f.type != "button") {
if (f.required == true && (f.value == "" || f.value == "Off")) {
c++;
}
}
}
if(c == 0){
this.mailDoc({ //change the emails, etc. as needed
bUI: false,
cTo: "xxx@xxx.com",
cCC: "",
cSubject: "Form filled",
cMsg: "My info attached"
});
}
else {
app.alert("At least one required field is empty...",1);
}
Copy link to clipboard
Copied
I don't see any saveAs in your code. Please show us the failing code, and tell us any errors in the console.
Copy link to clipboard
Copied
Hi Legend, thank you for your rapid response.
Code with menuitem saveAs below.
However I think I have found the issue - in posts elewhere it appears that Save and SaveAs in Acrobat / Reader are protected operations for security reasons.
Once I added the folder into my Reader DC's Privileged Locations it worked fine (which is not much use for someone else filling the form).
There were also posts regarding trusted functions etc. However there seems no simple way to have a PDF form that allows code to check the required fields and have the user save a copy to their local PC. I tried a trial copy of both Acrobat and Soda and the strange thing is that I could add a 'SaveAs' action button in Soda that worked - although I could not see what code was used - just something called a 'Named Action', thus I could not add code to the button to check the required fields. BTW the Soda 'named action' still worked when the PDF was opened in Acrobat. How is that SaveAs not a protected operation?
Also using Acrobat it appears required fields only work if you 'distribute' the form, which somehow changes the nature of the PDF so that clicking on Submit Form checks the required fields. Why is this necessary?
The 'distributed' form checking does not work in Soda, Wondershare PDF Elements - so much for PDF being a generic format.
That is why I chose to use code to check the required fields - which works fine for emailing the form, (on all readers) but will not for SaveAs. Frankly it seems very poor that we need to go to so much trouble to make use of required fields - they should just work.
Here is the code with saveAs:
var c = 0;
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f.type != "button") {
if (f.required == true && (f.value == "" || f.value == "Off")) {
c++;
}
}
}
if(c == 0){app.execMenuItem("SaveAs");
}
else {
app.alert("At least one required field is empty...",1);
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more