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

Locking a PDF Form

Community Beginner ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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

Views

557

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

correct answers 1 Correct answer

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

 

 

Votes

Translate

Translate
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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? 

 

 

 

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

 

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

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

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