Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to check if all required fields have been filled in before submitting a document as read only?

New Here ,
Oct 29, 2018 Oct 29, 2018

Hello,

I am making a form with required fields. I would like the form to do the following when the submit button is pushed:

1: check to make sure all required fields are filled out.

  •      if all fields are filled in then, form converts to read only
  •      if not all fields are fill in then, user is notified that not all fields are filled in

2:  Once form is read only, send email with subject as one of the fields

I have been researching this for weeks and have been trying lots of options, but haven't found one that works. Any help is appreciated! Thanks!

TOPICS
PDF forms
7.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Oct 29, 2018 Oct 29, 2018

You can use this code to achieve it:

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f = this.getField(this.getNthFieldName(i));

     if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {

        emptyFields.push(f.name);

    }

}

if (emptyFields.length>0) {

     app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));

} else {

    for (var i=0; i<this.numFields; i++) {

        var f = this.getField(this.getNthFieldName(i));

        if (f!=null) f.readonly = true;

    }

    var subjectLine = this.getField("Text1").valueAsString;

    var msgBody = "This is the message body of the email";

    this.mailDoc({cTo: "me@server.com", cSubject: subjectLine, cMsg: msgBody});

}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2018 Oct 29, 2018

You can use this code to achieve it:

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f = this.getField(this.getNthFieldName(i));

     if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {

        emptyFields.push(f.name);

    }

}

if (emptyFields.length>0) {

     app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));

} else {

    for (var i=0; i<this.numFields; i++) {

        var f = this.getField(this.getNthFieldName(i));

        if (f!=null) f.readonly = true;

    }

    var subjectLine = this.getField("Text1").valueAsString;

    var msgBody = "This is the message body of the email";

    this.mailDoc({cTo: "me@server.com", cSubject: subjectLine, cMsg: msgBody});

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 29, 2018 Oct 29, 2018

Thanks so much! This worked perfectly!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 26, 2023 Aug 26, 2023
LATEST

In what way 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines