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

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

Community Beginner ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

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

Thank you!

TOPICS
Acrobat SDK and JavaScript

Views

10.4K

Translate

Translate

Report

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 ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 Beginner ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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??

Votes

Translate

Translate

Report

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 ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 Beginner ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 Beginner ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
May 06, 2016 May 06, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
May 06, 2016 May 06, 2016

Copy link to clipboard

Copied

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??

Votes

Translate

Translate

Report

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 Beginner ,
May 06, 2016 May 06, 2016

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

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 ,
May 07, 2016 May 07, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
May 08, 2016 May 08, 2016

Copy link to clipboard

Copied

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;

        } 

    }

Votes

Translate

Translate

Report

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 ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 Beginner ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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).

Votes

Translate

Translate

Report

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 Beginner ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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()

}}

Votes

Translate

Translate

Report

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 ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

Are you getting any errors on the JavaScript console?

Votes

Translate

Translate

Report

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 Beginner ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
May 09, 2016 May 09, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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