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

Locking a PDF Form

Community Beginner ,
Jul 21, 2022 Jul 21, 2022

I am trying to create a form. My goal is to have the form lock itself when a specific text box (not signature) is completed. Is there a way to do this?

TOPICS
Create PDFs , PDF forms
1.8K
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 ,
Jul 22, 2022 Jul 22, 2022

Create a button field and as its Mouse Up event have it run the following JavaScript code:

 

 

if (app.alert("Are you sure you want to finalize the file?",2,2)==4) {
	if (app.viewerType=="Reader") {
		for (var i=0 ; i<this.numFields ; i++) {
			var f = this.getField(this.getNthFieldName(i)) ;
			if (f==null) continue;
			if (f.type=="button" || f.type=="signature") continue;
			f.readonly = true;
			f.defaultValue = f.valueAsString;
		}
	} else {
	   this.flattenPages();
	}
}

 

 

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 ,
Jul 21, 2022 Jul 21, 2022

You can achieve that with a JavaScript script.

 

Do you intend to keep that field lock after it is completed or do you intend to give the user an option to revert the field to unlock if other conditions are met? 

 

 

 

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 Beginner ,
Jul 21, 2022 Jul 21, 2022

Thank you! I intend to keep it locked, I believe.

 

Essentially, I need to create a form where person A completes the form as fully as possible and once done, emails it to person B. Once it is edited to person B's standards, they complete the specific field and when they save, the entire form becomes locked/read-only.

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 ,
Jul 22, 2022 Jul 22, 2022

A digital signature is the best way to do that. Any other form of "locking" can easily be reversed, if someone is willing to do so and has access to the right tools.

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 Beginner ,
Jul 22, 2022 Jul 22, 2022

I don't mind if it can be reversed, that would be fine. It doesn't need to be locked for safety. I'm just looking to make it read-only when completed.

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 ,
Jul 22, 2022 Jul 22, 2022

Then you can do it using this script:

 

if (app.viewerType=="Reader") {
	for (var i=0 ; i<this.numFields ; i++) {
		var f = this.getField(this.getNthFieldName(i)) ;
		if (f==null) continue;
		if (f.type=="button" || f.type=="signature") continue;
		f.readonly = true;
		f.defaultValue = f.valueAsString;
	}
} else {
   this.flattenPages();
}
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 Beginner ,
Jul 22, 2022 Jul 22, 2022

Thank you!!! Forgive my ignorance as I'm very new to this world. How do I add this in?

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 ,
Jul 22, 2022 Jul 22, 2022

What do you want to trigger this? You wrote that it should happen when a specific text box is completed, but I would recommend you reconsider that. What if someone makes a mistake and wants to change it later on? The fields would already have been locked and they couldn't do it...

I would recommend using a button, instead. You can even add a confirmation dialog to the code, to make sure they want to finalize the file.

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 Beginner ,
Jul 22, 2022 Jul 22, 2022

A button would work great as well! Any guidance for that would be great too.

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 ,
Jul 22, 2022 Jul 22, 2022

Create a button field and as its Mouse Up event have it run the following JavaScript code:

 

 

if (app.alert("Are you sure you want to finalize the file?",2,2)==4) {
	if (app.viewerType=="Reader") {
		for (var i=0 ; i<this.numFields ; i++) {
			var f = this.getField(this.getNthFieldName(i)) ;
			if (f==null) continue;
			if (f.type=="button" || f.type=="signature") continue;
			f.readonly = true;
			f.defaultValue = f.valueAsString;
		}
	} else {
	   this.flattenPages();
	}
}

 

 

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 Beginner ,
Jul 22, 2022 Jul 22, 2022

YES! Worked perfectly. Thank you so, so much.

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 ,
Jul 22, 2022 Jul 22, 2022
LATEST

Be aware that if this is used in Acrobat the process is not reversible, though.

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