Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Looking to lock form on email submission and set something from the form in the email subject

Avatar

Level 3

I have added an email submission button. I've looked around but can't seem to find the answer to this - how do I lock the form on submission? The form has an auto-populate today's date box, and currently every time I open the form it resets it to the current date. 

Second, I have fields on the form for "forename" and "surname". Would it be possible to have the following in the "email subject": 

[specific text] - (forename initial) (surname initial)

 

Thanks!

61 Replies

Avatar

Employee

Hi,

you are running code in initialize and layout:ready. The initialize script is not surrounded by an if - hence it ALWAYS sets the date field.

Avatar

Level 3

Ah, is that the problem. Should I move this script:

if ($ == null) then
$.rawValue = Num2Date(date(),"YYYY-MM-DD")
endif

To the top of the script box?

Avatar

Employee

no just run the script with the surrounding if in ONE event only - either initialize or layout:ready but not in both and not without if.

Avatar

Level 3

So have just this in the script box? -

form1.Page1subform.Datenamegradesubform.DateField1::ready:layout - (FormCalc, client)

if ($ == null) then
$.rawValue = Num2Date(date(),"YYYY-MM-DD")
endif

Avatar

Employee

these are fixed headlines - you cannot delete them.

Avatar

Level 3

That seemed to do it! I now have a useable form and should be able to make the final tweaks myself. Thanks so much for your input! Do you have somewhere I can contribute to you or a charity?

Avatar

Level 3

Hi Kosta,

One thing I've noticed - when I save the form in Adobe Abrobat DC as a "Reader Extended PDF / enable more tools (includes form fill-in & save), then the current date & current time fields lock at that point - not when the form is filled in & the submit button pressed. 

Am I doing something wrong here? I wanted to save it as a Reader Extended PDF so that users can fill the form in. Thanks!

Avatar

Level 4

Happy that it finally works out for you... don't worry about contributions - I help when I can and when I have the time

When you open that form with the extensions in Adobe Acrobat DC - does it also lock or only in Adobe Reader? Did you enter anything in that date field prior to saving it in Acrobat DC? You may have inadvertently filled the field so that it does not contain null any more. Do you have the original without extensions?

Avatar

Level 3

After saving the form in Designer, I can open it in either Adobe Acrobat or Adobe Acrobat Reader with no problem - the time field is refreshed each time I open it (as planned). If I open it with Adobe Acrobat and then save as a "reader extended pdf" with "enable more tools", then when I open the form again (either in Adobe Acrobat or Adobe Acrobat Reader) the time field is not updated - it is locked at the time when I saved as a reader extended pdf.

When I open the file in Acrobat to save it as a reader enabled pdf, the current date & time field is automatically populated as planned - I don't need to enter anything in it. So it isn't empty at the point of saving as a reader enabled pdf. But I thought that the field only locked when the submit button is clicked?

I'm not sure what you mean when you ask if I have the original without extensions.

Avatar

Employee

Hi,

this is a bit of hen and egg. The field fills in a date/time when the field as empty (null) initially. When you save it with REs  you save the prefilled date which in turn locks the date field. catch 22....

I need to think about a way to prevent the field to be filled when applying REs with Acrobat Pro.

Avatar

Level 3

Catch 22 situation  

Can we set the script to only lock those fields when the submit button is pressed?

Avatar

Employee

ok, here is how this will work:

1) check if the prefill logic for your fields are in the ready:layout or initialize event. If they are in the layout:ready they must be moved to initialize or the fields cannot be made empty (they immediately fill themselves again after clearing them).

2) Open the original PDF in Acrobat and make sure you emptied the content of all fields which should be filled later (Date...)

3) Save with RE after you have cleared the fields

 

That worked here.

Avatar

Level 3

I changed the script type from layout:ready to initialise, for both the current date and current time fields (which have scripts to auto-populate). When I then save the form and open it in Acrobat, these 2 fields are empty. I save the form as reader enabled, then open it in Acrobat Reader. The fields are still empty. I complete the form and click submit - the form is attached to an email, as we planned. If I open that form however, those 2 fields are still empty! Now they don't seem to auto-populate at all.

Hang on - I changed the script type to formcalc. Now the fields do auto populate - but they are locked when I save it as a reader enabled (the same problem I had before). When I subsequently open the form in Acrobat Reader, the time is locked already.

As a reminder, this is the script in the auto-populated time field:

if ($ == null) then
$.rawValue = Num2Time(Time(), "HH:MM")
endif

Avatar

Employee

@lostfroggdid you empty the fields manually before you saved the RE version?

Avatar

Level 3

You mean empty them in Adobe Acrobat? When I try and edit the form in Acrobat, it says "This form cannot be edited in Adobe Acrobat DC. Please use Adobe LiveCycle Designer to edit this form."

Avatar

Employee

no  not edit the form. You open the non-RE PDF and get your fields pre-filled with the current date. Go into those fields with the mouse and empty them by deleting the currently pre-filled date/time. Having the script in the initialize prevents the form from overwriting it again as soon as you leave the field. When all your fields are empty then save as RE PDF and that always starts with empty fields to be pre-filled by your scripts instead of locked fields.