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

Lock form & email as PDF Javascript

Guest
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

Hi Guys,

I am using Adobe Acrobat X and creating a Forms natively. We do not use LiveCycle.

So I have created a form with several fields, buttons a date picker - some of which I have found online.

The forms that I will be creating will be placed on the Intranet of the Organisation that I work for.

So what I need is for our users to fill out the form online. Press the Submit button. When they press submit the form must lock all the contents. We do not want to contents edited when it reaches its destination. The submit button will also call up the default email program, populate the TO: field with a specified email address and the Subject field with specified text.

The form must arrive at its destination in PDF format.

Been stuck on this one for a while. I used some simple html with the submit button for a while and that mostly worked except the part about locking the form.

So if someone can java me up a solution i would greatly appreciate it.

I have tried a few of the solutions a few solutions from the lifecycle partof the forum but apparently the java is different!

Many thanks,

Nick

Views

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

correct answers 1 Correct answer

Community Expert , Mar 21, 2012 Mar 21, 2012

I've written an improved version of the code mentioned. This version will completely flatten the file when used in Acrobat, but will just make the fields read-only when used in Reader.

flattenFields()

function flattenFields() {

    if (app.viewerType=="Reader") {

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

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

            if (f==null) continue;

            f.readonly = true;

        }

    } else {

        this.flattenPages();

    }

}

Votes

Translate

Translate
Community Expert ,
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

Is the file going to be used in Acrobat or in Reader?

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
Guest
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

The users filling the form out will be mixed. Some will have writer, others will have Reader only.

Thanks for the swift response

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 ,
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

In that case you can only set the fields as read-only, not truly flatten

them. Here you'll find a script I posted that will do that:

http://acrobatusers.com/forum/forms-acrobat/i-need-users-fill-form-and-save-it-then-it-shouldnt-be-anymore-editable/

Regarding submitting the file by email and pre-populating the various

fields, see this:

http://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address

The variabt you should use is mailDoc().

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 ,
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

I've written an improved version of the code mentioned. This version will completely flatten the file when used in Acrobat, but will just make the fields read-only when used in Reader.

flattenFields()

function flattenFields() {

    if (app.viewerType=="Reader") {

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

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

            if (f==null) continue;

            f.readonly = true;

        }

    } 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
Guest
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

Thank you so very much. I have implemeted a form using your code on our Development site and it works like a dream.

Thanks again

Nick

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
Guest
Mar 22, 2012 Mar 22, 2012

Copy link to clipboard

Copied

Hi,

Not to sound ungreatful but, I have just noticed that the flattening of the document means that the form can be submitted without Required Fields being filled in. Is this an easy fix?

Regards,

Nick

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 ,
Mar 22, 2012 Mar 22, 2012

Copy link to clipboard

Copied

You sholdn't flatten it if you want to use the built-in validation process triggered when the file is submitted. Use just the option that makes the fields 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
Guest
Mar 22, 2012 Mar 22, 2012

Copy link to clipboard

Copied

So there is an option that sets the fields to Read Only after the user has filled out the form and submitted?

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 ,
Mar 23, 2012 Mar 23, 2012

Copy link to clipboard

Copied

Yes, the code from my original response does that (as well as the later response, if the file is used in Reader).

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
Guest
Mar 26, 2012 Mar 26, 2012

Copy link to clipboard

Copied

Cheers for that. I have chucked that in there. But what happens now is if the form is submitted without all fields being filled the form gets locked from editing and the user gets stuck with having to get out of and re-open the form and start again.

Anyway to have some sort of a prior check the make sure all required fields are filled in PRIOR to the form being marked as Read Only? That way the user can go back and rectify any errors.

Sorry to be a pain the ...!!

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
New Here ,
Mar 26, 2013 Mar 26, 2013

Copy link to clipboard

Copied

Hello,

I have a form that I want the user to be able to complete  in Adobe Reader.  I'd like users to add text to form fields up until they submit the form.  At submission the form would be locked and no changes  made.   The discussion above does most of what I want with the exception of a Print button and Save button.  I don't want them locked. Is there a way to lock everything except these two buttons.

When I include the above script to one of the buttons  the document locks,  and although, the buttons are set as "visible but doesn't print" they print anyway.

Any help would be appreciated.

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
Guest
Jan 12, 2015 Jan 12, 2015

Copy link to clipboard

Copied


I would like to know how I can lock only selective fields

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
Guest
Feb 04, 2016 Feb 04, 2016

Copy link to clipboard

Copied

Here's a script I've been using for years, although it only locks the fields. Any ideas as on how to modify it to submit a form as well?

     for

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

     {var fname = this.getNthFieldName(i);

     var f = this.getField(fname);

     if (f.type!="button") f.readonly = true;}


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 ,
Feb 04, 2016 Feb 04, 2016

Copy link to clipboard

Copied

At the end of the code add this line:

this.submitForm({cURL: "enter your target URL here"});

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
Explorer ,
Oct 19, 2020 Oct 19, 2020

Copy link to clipboard

Copied

Question - to use the above to keep selective fields unlocked, can you list each field name, and then set them to readonly = false?

 

I'm trying to make a 2-page form locked, once emailed, but leave 8 fields unlocked for input once the Administrator receives the email with attached PDF.

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 ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

You can use this code to do it. Specify the names of the fields to "skip" (ie. keep editable) in the first line:

 

Edit: Small mistaked in the code fixed.

 

 

var fieldsToSkip = ["Text1", "Radio2", "Checkbox3"];
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f!=null && fieldsToSkip.indexOf(f.name)==-1 && f.type!="button") 
		f.readonly = true;
}

 

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
Explorer ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

I amended the script behind my "submit" button with the above, but I am receiving an error message.  Since I know very little about JS, I cannot figure out what is causing the error.  I would appreciate assistance with recommended changes to the following so this will work:

var ok = true;

var i = 0;

var fieldsToSkip = ["RU.Case#", "RU.Department", "RU.Cost Center","RU.Company Code", "RU.Location Address", "RU.FTE", "RU.Job Title", "RU.Reports To", "RU.Hire Date","RU.Other"];
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f!=null && fieldsToSkip.indexOf(f.name)==-1) && f.type!="Click to Submit")
f.readonly = true;
try{

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

if(f.required==true){

if(f.value==f.defaultValue && f.type != 'button' && f.type != 'signature'){

ok=false;app.alert('Your Report cannot be submitted because the following field(s) are blank: '+f.name);

}

}

}catch(ex){};

};

if(ok==true){

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

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

f.readonly = true;

};
var fld = this.getField("Date Signed");

fld.value = util.printd("mmmm dd, yyyy HH:MM:ss",new Date());

var to = "emailme@domain.com";

var strUrl = "mailto:"+to+"?subject=Report&body=Attached is my completed Report&cc=&bcc=";

var submitAs = "PDF";

this.submitForm({cURL: strUrl, cSubmitAs:"PDF"});

};

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 ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

What does the error message say, exactly?

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
Explorer ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

The message is:

Syntax Error:  missing ) after argument list 8: at line 9

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
Explorer ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

LATEST

Ok,  after removing the ), I now receive "syntax error 9: at line 10 (which is f.readonly = true;).

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 ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

Remove ) at the end of

fieldsToSkip.indexOf(f.name)==-1)

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