Skip to main content
Participant
December 24, 2020
Question

Acrobat PDF-Formular - check Checkboxes, set all Fields to unchangeable and send a E-Mail

  • December 24, 2020
  • 1 reply
  • 914 views

Hello,

i am new here. I've searched the forums and Googles and can't find an answer to my problem.
My Document is doing well to this time. But i need some help to complete all routines in the PDF.

i am missing a little addition in the script that will check the eight checkboxes. But the User of the PDF do not need to activate all checkboxes. It will be enough to activate only one of the eight. Only if none of all checkboxes are active some message should appear with a hint to check minimum one of all.

At least i need a code to set all Fields to unchangeable before sending the PDF.

I tried very hard, but i still make no progress.

Do anyone have an idea? It will be great to have some ideas.

Kind regards
dani75.com

 

Here the current Code:

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("ACHTUNG! Dieses Formular ist nicht vollständig:\nBitte folgendes Feld ergänzen: " + emptyFields.join("\n"));
}else{
sendMail();
}
var sendMail = function(){
var theCompany = this.getField("Feldname1").value;
this.mailDoc({
bUI: false,
cTo: "email@Adress.com",
cSubject: "Text",
cMsg: "Text"});
}

This topic has been closed for replies.

1 reply

ls_rbls
Community Expert
Community Expert
December 26, 2020

I am not sure if the script below works or not because I don't have a way to test it with no PDF.

 

Maybe if you can share an example of the PDF it will be easier to test.

 

However, see below.

 

I think that in the scond part of your script you were missing a condition to check if there are no empty fields and to make all fields readonly.

 

} else {

var sendMail = function(){
var theCompany = this.getField("Feldname1").value;
this.mailDoc({
bUI: false,
cTo: "email@Adress.com",
cSubject: "Text",
cMsg: "Text"});
}
if (emptyFields.length = 0) {
f.readonly = true; 
sendMail();
}

 

Participant
December 26, 2020

Dear ls_rbls,

thank you very much for your time to write me. In the meantime i´ve found a solution for the PDF Document. The Code is like beginners, but it works great for me.

Here ist the script:

 

 

var cntr = 0;
for (var a = 0; a < this.numFields; a++) {
var mf = this.getField(this.getNthFieldName(a));
if (mf.type != "button") {
if (mf.value == "Off") {
cntr++;
}
}
}
if (cntr > 😎 {
app.alert("Aktivate only one of eight Buttons!"); stopp;
} else {
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("Check the required Field: " + emptyFields.join("\n"));
}else{
for (var d = 0; d < this.numFields; d++){this.getField(getNthFieldName(d)).readonly=true;}
sendMail();
}
var sendMail = function(){
var theCompany = this.getField("Company").value;
this.mailDoc({
bUI: false,
cTo: "E-Mail@adress.com",
cSubject: "Text",
cMsg: "Text"});
}}

try67
Community Expert
Community Expert
December 26, 2020

There's no need to use a separate function. Try this:

 

if (emptyFields.length > 0) {
	app.alert("Check the required Field: " + emptyFields.join("\n"));
} else{
	for (var d = 0; d < this.numFields; d++) {this.getField(getNthFieldName(d)).readonly=true;}
	var theCompany = this.getField("Company").value;
	this.mailDoc({
		bUI: false,
		cTo: "E-Mail@adress.com",
		cSubject: "Text",
		cMsg: "Text"});
}