36 Replies Latest reply on Mar 19, 2017 5:41 AM by Karl Heinz Kremer

    How do I disable all fields when sending a pdf through the "submit a form" button?

    southwestd17121417

      I want to make sure that the fillable fields will not be editable when received via email.

       

      Thank you!

        • 1. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
          Karl Heinz Kremer Adobe Community Professional

          If this solution needs to work in both Adobe Acrobat and the free Adobe Reader, your only option is to set the fields to read-only in your form. You can do this by running a loop over all fields and then set the "readonly" property to "true":

           

          for (var i=0; i<this.numFields; i++) {
              this.getField(this.getNthFieldName(i)).readonly = true;
          }
          

           

          Depending on how your button is set up, you may have to add two different actions (or add this script to your already existing JavaScript action):

           

          2016-05-05_09-01-06.png

          • 2. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
            southwestd17121417 Level 1

            That's fantastic. (And forgive me for my lack of knowledge with regard to Adobe Acrobat...I'm learning, but it's going slowly..) The ultimate goal is that the "disabled" form is only disabled when it is sent via email. Now the issue I'm running into is that the code also locks the "reset form" button which is crucial for filling out the document again for a new client.  Any solutions??

            • 3. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
              Karl Heinz Kremer Adobe Community Professional

              Yes, these few lines will set all fields to read-only, regardless of what they are. If you want to exclude certain fields based on their name, you can do that, but you can also exclude e.g. all buttons. If there are no other buttons besides the reset and the submit button, that would be the most straight forward way of doing this. If there are other buttons, you would have to use the field name to find out if it's one of the fields you want to retain as interactive.

               

              The following script will exclude all buttons:

               

              for (var i=0; i<this.numFields; i++) {
                  var f = this.getField(this.getNthFieldName(i));
                  if (f.type != "button") {
                      f.readonly = true;
                  }
              }
              

               

              You would have to change your reset action to also change the form fields to read/writeable again. However, the better solution would be to never save the modified file after it's submitted, and always start with a fresh copy from the disk when you want to start with a new client.

              • 4. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                southwestd17121417 Level 1

                That makes so much sense, however, the sales guy MIGHT want to save the version that he's working on in case he's not yet ready to submit. I just want to be sure I've give him the easiest way to start a fresh form and I'm totally open to suggestions.

                 

                If the best bet is to make the form fields read/writable again is through a script, would you happen to have an easy one to share?

                • 5. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                  Karl Heinz Kremer Adobe Community Professional

                  You can just use the original script that I've posted and change the "true" to "false" when setting the "readonly" property.

                  • 6. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                    southwestd17121417 Level 1

                    That's amazing. You just taught me so much. Thank you. One last question: I have set the "clear form" and "send as email" buttons to hide when the email is sent. Is there a way to make those buttons show back up after the filled-out form has been submitted. I'll be protecting the original form so that my formatting/rules can't be changed, but I do need them to be able to control these two buttons.

                    • 7. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                      southwestd17121417 Level 1

                      I think I may have answered my own silly question...I think this is just a "visible but doesn't print" issue...

                      • 8. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                        Karl Heinz Kremer Adobe Community Professional

                        That's one option (especially if the output gets printed), but you can also add another action to your submit button: I guess you already have two:

                        - The JavaScript action to set the fields to read-only

                        - The "Submit a form" action to actually send your form

                         

                        Just add a third one that run another JavaScript in which you show these buttons again. The property you need to use is the Field.display property, which can be set to the values you can find here: Acrobat DC SDK Documentation

                        • 9. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                          southwestd17121417 Level 1

                          I tried that and it's keeping the active "clear form" and "submit" buttons in the email, meaning the recipient can use them. Is it simply re-ordering the list? I'm so grateful for you help - thank you.

                          • 10. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                            Karl Heinz Kremer Adobe Community Professional

                            What you have to do is change the status of these fields before you run the "Submit a form" action - in the same script that you set the other form fields to readonly. You've used this script (it's the same from above) to filter out buttons and set the other fields to readonly:

                             

                            for (var i=0; i<this.numFields; i++) {  
                                 var f = this.getField(this.getNthFieldName(i));  
                                 if (f.type != "button") {  
                                      f.readonly = true;  
                                 }  
                            } 
                            

                             

                            If you change the criteria and look for fields that are buttons, you can set these to display.hidden. And, because of the features of JavaScript, we don't have to write a new loop, we can actually use the same loop and the same test, just use the "else" branch of the if statement:

                             

                            for (var i=0; i<this.numFields; i++) {  
                                 var f = this.getField(this.getNthFieldName(i));  
                                  if (f.type != "button") {  
                                      f.readonly = true;  
                                 } 
                                 else {
                                      f.display = display.hidden;
                                 }
                            } 
                            

                             

                            Again, to reverse this after the form is submitted, you set readonly to true and you set display to display.visible.

                            • 11. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                              southwestd17121417 Level 1

                              I can't thank you enough for this help. I wish I had messaged you earlier with this question, but I thought I had it! So, I am trying to use the script above to lock all fields/hide buttons and then I need to email it which should prompt the fields to unhide/unlock (using code above again). However, none of the email/submit scripts that I'm trying are working at all, let alone letting me attach the PDF. Can you help??

                              • 12. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                southwestd17121417 Level 1

                                This is the code that I'm using...bear in mind that this is my first time to ever ever LOOK at Javascript, so I know it's pretty piecemeal Thank you again.

                                 

                                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

                                 

                                 

                                // The text in a Question Alert Box is usually in two parts.  A short explaination

                                // and the actual question.  It's a good practice to separate the question from the

                                // explaination by a line, In the text below, this separation is accomplished

                                // with the escaped line feed characters "\n\n"

                                //

                                // The alert box will only show about 6 lines of text, so both explainations and

                                // text should be kept short

                                var cMsg = "Have you confirmed that all fields are complete and accurate?";

                                cMsg += "\n\n Form will lock upon sending.";

                                 

                                var nRtn = app.alert(cMsg,2,2,"Question Alert Box");

                                if(nRtn == 4)

                                {// A yes Response

                                  // Code for doing the thing you do on a yes

                                  console.println("The Response Was Yes");

                                 

                                var answer = app.alert("Are you sure you're ready to submit Production Form for quote? ", 2, 2);  

                                 

                                /* Question icon, Yes/No button. */

                                /* 0 = error, 1 = OK, 2 = Cancel, 3 = No, 4 = Submit Form */

                                {

                                }

                                 

                                if (answer == 3)

                                {

                                }

                                 

                                if (answer == 4)

                                 

                                {

                                 

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

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

                                          if (f.type != "button") {  

                                              f.readonly = true;  

                                         } 

                                         else {

                                              f.display = display.hidden;

                                         }

                                    }  }

                                 

                                 

                                var Subject_Line = getField("New Construction Door Production Form").value

                                 

                                var Subject_Line2 = getField("Customer Name").value

                                 

                                    this.mailDoc({

                                 

                                        cTo: "mailto:user@domain.com",

                                 

                                        cSubject: Subject_Line+"_"+Subject_Line2,

                                         cMsg: "Quote requested: New Construction Exterior Door. Thank you!"

                                 

                                    });

                                }

                                else if(nRtn == 3)

                                { // No Response

                                  console.println("The Response Was No");

                                }

                                else 

                                { //Unknown Response

                                  console.println("The Response Was somthing other than Yes/No: " + nRtn);

                                }

                                • 13. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                  Karl Heinz Kremer Adobe Community Professional

                                  There is something wrong with your code. I think you need to add a {} pair:

                                   

                                  if (emptyFields.length > 0) {
                                    app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
                                  }
                                  else
                                  { // <- added
                                  

                                   

                                  and then a "}" after the last line.

                                   

                                  Also, you have a "{}" in the middle of your script, which does not do anything:

                                   

                                  /* Question icon, Yes/No button. */
                                  /* 0 = error, 1 = OK, 2 = Cancel, 3 = No, 4 = Submit Form */
                                  {
                                  }
                                  

                                   

                                  And, this is also not doing anything:

                                   

                                  if (answer == 3)
                                  {
                                  }
                                  

                                   

                                  It also looks like you are not reversing the change you make to the form fields after the forms submission: You are not setting the fields back to readonly = false and display = display.visible

                                   

                                  You may want to do yourself a favor and get a good introduction to JavaScript to get a better understanding of the syntax of the language. There is only so much you can pick up from forum posts and via Google, a step by step introduction will give you a good foundation to built your own solutions on. I understand that this requires a serious tie commitment, but believe me, in the long run, you are saving time and money. One resource I like a lot is this: Beginning JavaScript for Adobe Acrobat - this is just about Acrobat's JavaScript implementation and does not confuse you with things that are e.g. only available in the web browser.

                                  • 14. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                    southwestd17121417 Level 1

                                    Thank you so much for the resource. I have bookmarked it and have been referencing it quite a bit. I'm stuck on something that I can't figure out though and I think it's going to be a simple answer. With the code that I'm using to hide the buttons up submitting, I do need one button, the print button, to stay active so that the end user can print the PDF with the locked fields. Below is the script that I've been using to call out the exception, but it's not working and I can't tell where I'm wrong. Thank you again.

                                    {

                                     

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

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

                                              if (f.type != "button") {   

                                                  f.readonly = true;   

                                             }  

                                             else { 

                                                  f.display = display.hidden; 

                                     

                                    var a = this.getField("Print");

                                    a.readonly = false;

                                     

                                            } 

                                        }

                                    • 15. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                      Karl Heinz Kremer Adobe Community Professional

                                      What exactly happens when you try to run your code? Are you getting errors on the JavaScript console?

                                       

                                      In general, your loop tests for the field type, and if the field type is not "button", it will set the field to read-only. If the field type is "button", then it will run the few lines that get the "Print" field and set that to read/writable. You are doing this any time your field type is of type "button", so it's getting executed too often, but it should not be doing any harm.

                                       

                                      However, there is a better way of doing this:

                                       

                                      for (var i = 0; i < this.numFields; i++) {
                                        var f = this.getField(this.getNthFieldName(i));
                                        if (f.type != "button") {
                                             f.readonly = true;
                                        } else {
                                             if (f.name == "Print") {
                                                  f.readonly = false;
                                             }
                                        }
                                      }
                                      

                                       

                                      As you can see, in the loop, we can test the field name and then execute a certain command only if the name matches a string.

                                      • 16. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                        southwestd17121417 Level 1

                                        That worked beautifully, except for now the darn "Send as Email" (submit) button is also still active after the pdf is received via email!

                                        • 17. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                          Karl Heinz Kremer Adobe Community Professional

                                          OK, so the only buttons that should remain active are the "Print" and the "Reset" button?

                                          • 18. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                            southwestd17121417 Level 1

                                            Actually, only the Print button. I don't have a reset button, per se, because the "Send as Email" button includes all of the script to lock, send and then reset the form upon send. The 'Send as Email' simply hides in emailed form and then should be reset with the rest of the form upon send.

                                            • 19. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                              southwestd17121417 Level 1

                                              I'm running into another issue that I'm more more concerned about right now...I've read a lot about how PDFs with javascript don't work well with ipads/iphones well with most viewers, but that the Readdle's PDF Expert will actually work. (The sales guy will be using this in the field and he needs an extremely portable device.) All seems to be working well EXCEPT for the drop down arrows. When I open the emailed form on a computer, the arrows are not visible, but when I open the same emailed form via PDF Expert, you can still see the drop down arrows and they actually hide the actually data that I'm trying to see.

                                               

                                              It doesn't matter that the arrows show on the template form because the "pop-up" screen appears with the drop down list, of course.

                                               

                                              Is this something that I can fix or should accept and move on?

                                              • 20. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                Karl Heinz Kremer Adobe Community Professional

                                                In that case, change lines 6-8 in my last script to this:

                                                 

                                                 

                                                f.readonly = (f.name != "Print"); 

                                                 

                                                • 21. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                  Karl Heinz Kremer Adobe Community Professional

                                                  That is a question you need to ask the folks at Readdle. I suspect that this is a bug in their application, and only they can fix it (or tell yo if there is a workaround).

                                                  • 22. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                    southwestd17121417 Level 1

                                                    This form is killing. I tried that - see script below and nothing. The send as email and print buttons are both still active when the email attachment is opened.

                                                     

                                                    {

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

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

                                                          if (f.type != "button") {

                                                               f.readonly = true;

                                                          } else {

                                                             f.readonly = (f.name != "Print");

                                                               }

                                                          }

                                                      

                                                        

                                                     

                                                    {

                                                    var myDoc = event.target;

                                                        var cToAddr = "user@domain.com";

                                                        var cSubLine = "cust," +": New Construction Exterior Door Production Form Attached";

                                                        var cBody = "Please let me know if you have any questions at all. Thank you!";

                                                        this.mailDoc({bUI:false, cTo:cToAddr, cCC:"", cSubject:cSubLine, cMsg:cBody});

                                                     

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

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

                                                              if (f.type != "button") {  

                                                                  f.readonly = false;  

                                                             } 

                                                             else {

                                                                  f.display = display.visible;

                                                             }

                                                        } 

                                                    this.resetForm()

                                                    }}

                                                    • 24. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                      southwestd17121417 Level 1

                                                      All I get is "Syntax Error" at line 84, which is the end of my script. I've tried to figure out where the missing piece is, but am at a loss

                                                      • 25. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                        Karl Heinz Kremer Adobe Community Professional

                                                        I am not getting an error with your code. You do not have 84 lines in your JavaScript, so the error must be somewhere else. Would you be able to share your PDF file? You can share it via e.g. Adobe's Document Cloud and then post the link here. You can find instructions about how to do that here: Share Documents via Adobe's Document Cloud - KHKonsulting LLC

                                                        • 26. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                          southwestd17121417 Level 1

                                                          Absolutely. I'm pretty embarrassed about the state of my coding, but it is what it is. Please don't judge. :/

                                                          Shared Files - Acrobat.com

                                                          • 27. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                            Karl Heinz Kremer Adobe Community Professional

                                                            There is a problem in the field that calculates today's date: The "then" "endif" statements look like they belong into a VB program, but not in JavaScript. Use the following instead:

                                                             

                                                            if (event.value != "")
                                                                event.value = util.printd("m/d/yyyy", new Date())
                                                            

                                                             

                                                            The rest seems to work, even though I don't understand what you are doing in your print function: It looks like you are setting all fields to "visible, but does not print" before you call the actual print function. This will not print anything that was entered in your form fields.

                                                            • 28. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                              southwestd17121417 Level 1

                                                              Thank you. I still can't seem to make it work. I've opted out of the print button, so basically, I just need the form to lock upon send, hide the email button and then reset itself after send with the email button reappearing. Everything is working now EXCEPT the stupid hiding the email button part. I've tried going back through the code and instructions that you gave above, but to no avail. Would you mind taking a look one more time for me? I'm desperate to finish this form.

                                                               

                                                              THANK YOU

                                                               

                                                              Shared Files - Acrobat.com

                                                              • 29. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                                Karl Heinz Kremer Adobe Community Professional

                                                                It looks like you went back a couple of versions, which his what broke a number of things (e.g. clicking on the "No" button does still submit the form).

                                                                 

                                                                Take a look at 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 {
                                                                
                                                                
                                                                    // The text in a Question Alert Box is usually in two parts.  A short explaination
                                                                    // and the actual question.  It's a good practice to separate the question from the 
                                                                    // explaination by a line, In the text below, this separation is accomplished
                                                                    // with the escaped line feed characters "\n\n"
                                                                    // 
                                                                    // The alert box will only show about 6 lines of text, so both explainations and  
                                                                    // text should be kept short
                                                                    var cMsg = "Have you confirmed that all fields are complete and accurate?";
                                                                    cMsg += "\n\n Form will lock upon sending.";
                                                                
                                                                
                                                                    var nRtn = app.alert(cMsg, 2, 2, "Question Alert Box");
                                                                    if (nRtn == 4) { // A yes Response
                                                                        // Code for doing the thing you do on a yes
                                                                        console.println("The Response Was Yes");
                                                                
                                                                
                                                                        var answer = app.alert("Are you sure you're ready to submit Production Form for quote? ", 2, 2);
                                                                
                                                                
                                                                        /* Question icon, Yes/No button. */
                                                                        /* 0 = error, 1 = OK, 2 = Cancel, 3 = No, 4 = Submit Form */
                                                                
                                                                
                                                                        if (answer == 3) {}
                                                                
                                                                
                                                                        if (answer == 4) {
                                                                            for (var i = 0; i < this.numFields; i++) {
                                                                                var f = this.getField(this.getNthFieldName(i));
                                                                                if (f.type != "button") {
                                                                                    f.readonly = true;
                                                                                } else {
                                                                                    if (f.name == "Send as Email") {
                                                                                        f.display = display.hidden;
                                                                                    }
                                                                                }
                                                                            }
                                                                
                                                                
                                                                            {
                                                                                var myDoc = event.target;
                                                                                var cToAddr = "user@domain.com";
                                                                                var cSubLine = "cust," + ": New Construction Exterior Door Production Form Attached";
                                                                                var cBody = "Please let me know if you have any questions at all. Thank you!";
                                                                                this.mailDoc({
                                                                                    bUI: false,
                                                                                    cTo: cToAddr,
                                                                                    cCC: "",
                                                                                    cSubject: cSubLine,
                                                                                    cMsg: cBody
                                                                                });
                                                                
                                                                
                                                                                for (var i = 0; i < this.numFields; i++) {
                                                                                    var f = this.getField(this.getNthFieldName(i));
                                                                                    if (f.type != "button") {
                                                                                        f.readonly = false;
                                                                                    } else {
                                                                                        f.display = display.visible;
                                                                                    }
                                                                                }
                                                                                this.resetForm()
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                

                                                                 

                                                                This should correctly hide and show the "Submit as Email" button.

                                                                • 30. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                                  southwestd17121417 Level 1

                                                                  It's perfect. I'm so happy I could cry, THANK YOU THANK YOU THANK YOU

                                                                  • 32. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                                    Karl Heinz Kremer Adobe Community Professional

                                                                    Would you mind marking whatever reply helped you as the correct answer to close this question?

                                                                    • 33. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                                      mnsnoopy

                                                                      I found your last post very helpful also and ran into one issue: I need to make the other buttons such as print and save as not visiable also before emailing the pdf. Here is your code:

                                                                       

                                                                      1. if (answer == 4) { 
                                                                      2.             for (var i = 0; i < this.numFields; i++) { 
                                                                      3.                 var f = this.getField(this.getNthFieldName(i)); 
                                                                      4.                 if (f.type != "button") { 
                                                                      5.                     f.readonly = true
                                                                      6.                 } else
                                                                      7.                     if (f.name == "Send as Email") { 
                                                                      8.                         f.display = display.hidden; 
                                                                      9.                     } 
                                                                      10.                 } 
                                                                      11.             } 
                                                                      12.  
                                                                      13.  
                                                                      14.             { 

                                                                       

                                                                      Where this if statement is, I need to also make two other forms not visible and tried to modify the code but it gives me errors

                                                                       

                                                                      if (f.name == "Send as Email") { 

                                                                                              f.display = display.hidden;

                                                                      if (f.name == "Save PDF Form") { 

                                                                                              f.display = display.hidden;

                                                                      if (f.name == "Print Form") { 

                                                                                              f.display = display.hidden;

                                                                      if (f.name == "Email Form") { 

                                                                                              f.display = display.hidden;

                                                                       

                                                                      You may not be watching this any longer but wanted to try anyway.

                                                                      • 35. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                                        try67 MVP & Adobe Community Professional

                                                                        You didn't close any of the curly bracket... Use this code instead:

                                                                         

                                                                        if (f.name == "Send as Email" || f.name == "Save PDF Form" || f.name == "Print Form" || f.name == "Email Form") {

                                                                            f.display = display.hidden;

                                                                        }

                                                                        • 36. Re: How do I disable all fields when sending a pdf through the "submit a form" button?
                                                                          Karl Heinz Kremer Adobe Community Professional

                                                                          You may want to get in touch with the author directly. I am not connected to the book or the website - I just know there book and recommend it.