Expand my Community achievements bar.

How do I lock all fields on submitting form?

Avatar

Level 3

I have a XML PDF form with a number of fields, including a few which auto-populate as per a script (e.g. today's time, today's date). Every time I open the (unsubmitted) form, these fields update as per the system date/time. This is expected.

I want all fields to lock when the user presses the submit button at the end of the form. Currently, even after the form is submitted, the PDF keeps updating those fields every time it is opened!

10 Replies

Avatar

Level 10

Hi there,

 

my best bet would be having a checkbox in background with visibility's set as hidden which you would set its value checked once the form is submitted.

When your code to set values is executed in the fields, simply verify that the checkbox is unchecked before setting any value.

 

Additionally, you can also have a single statement in the initialize event of each objects to set their access state to readOnly when the checkbox is checked.

 

Hope this will help.

Avatar

Level 3
Thanks Magus069. I'm pretty much a noob when it comes to this and have been trying to learn as I go along. I can put a checkbox on the form with visibility set to hidden - but how do I "set its value checked once the form is submitted"? And how to I have a statement to set their access state to readonly when the checkbox is checked? Thanks

Avatar

Level 10

Hi there,

 

The following link will explain how to submit a form using JavaScript.

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

 

Once you execute the code to submit a form, simply change the value of the checkbox to "checked" like the following:

//This should work if your checkbox object's value is either 1 or 0
CheckBox1.rawValue = "1";

//If you don't know for sure what's the object's value, you can use this
CheckBox1.rawValue = CheckBox1.getDisplayItem(0);

 

Once the check box is checked, you can have JavaScript code in the initialize event of each objects to set their access value to readOnly if the submit check box is checked

if (CheckBox1.rawValue == CheckBox1.getDisplayItem(0)){
     this.access = "readOnly";
} else{
     this.access = "open";
}

 

I hope this will help

Avatar

Level 3

Thanks Magus. I'm struggling to follow your instructions. @radzmar posted these instructions on another forum - would these work? This is for date but I would need something similar for time -

 

use this script in the form:ready event of your date field:

if ($.rawValue == null) then$.rawValue = Num2Date(Date(), DateFmt(4))else$.rawValueendif

Avatar

Level 10
I'm sorry I'm not sure what you are trying to accomplish using this code from radzmar for Time field?? Is this related to the same topic of this thread?

Avatar

Level 3
Yes, related to same topic. Sorry if the code I pasted isn't related. I found it in another thread and I thought it might be an easier way to accomplish what I am trying to do?

Avatar

Level 3
Hi Magus069, I'm still struggling with this; might it be possible to send you my form for you to take a look?

Avatar

Level 10
Yes you can, I'm sorry I forgot to reply this thread.

Avatar

Level 10

Hi there,

 

I am sorry I kind of mislead you here, as I thought you were handling things a bit differently.

By the look of how you are doing things it is much simpler than I said.

Technically there would be two things you need to consider, because I found an error while trying to fill in your form.

 

1st: As soon as the user hits submit and there's a field in the form that isn't valid, the form will stay read only because you set it "protected" inside the preSubmit event of the submit button.

To avoid this, you can simply set the form's access back to open in the postSubmit event. If you wish to set the form back to open only when the form isn't ready to be submitted I can provide the JavaScript to do so.

 

2nd: To avoid fields to be calculated every time the form is open once the form is locked, all you need to do is add a condition inside the calculate event of those fields like the following:

if (form1.access eq "open") then
     //calculate code
endif

 The code above matches the FormCalc that's used inside the calculate event of Current date and Current time.

If there's any other field that are using JavaScript, the syntax would need to be changed, but the logic is the same.

 

I hope this will help, let me know if you need anything else.

Avatar

Level 3

Hi Magus069,

 

Thanks for the further info. I pasted that script into the "calculate" fields for the current date and time. They are set to formcalc, and run at client. However, it's still not working; after converting to a "reader extended PDF", if I then complete and submit the form in Adobe Reader, whenever I open the submitted form in Adobe Reader, the time field still updates again.