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

Level 3

Open the non-RE PDF in which program? Adobe Acrobat? If I open it in Acrobat, then the pre-filled fields are not editable - I cannot select the text inside them to delete.

Avatar

Employee

Have you added logic that blocks those fields right from the start? Or what kind of PDF are you saving in Designer?

Avatar

Level 3

Not sure what you mean by logic that blocks those fields from the start. On the time field I have this script:

form1.Page1subform.Datenamegradesubform.DateTimeField1::initialize - (FormCalc, client)

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

In Designer I just save as a PDF. If I go to "save as", it seems to be saving as an "Adobe Dynamix XML Form (*.pdf)".

Avatar

Employee

when I do this with my form the fields are open and I can overwrite the date that was put in. Can you pass me your pdf so that I can have a look? Something is different between our two forms.

Avatar

Level 3

Just sent you a PM with a copy of my form - many thanks. 

Avatar

Level 3

Just added you to the shared list - should be OK for you now.

Avatar

Employee

got it and I see now that you made those 2 fields read-only - we need to think about how to solve this little conundrum.

I was confused about the locked thing. I will see if we can solve this.

Avatar

Level 3

Ah, I see. Is it as simple as turning off the read only function?

Avatar

Level 3

Really keen to get this issue finalised if anyone can help. Willing to share my form if that's of any assistance!

Avatar

Employee

Regarding your date field. Assuming that you used the Current Date field from the Custom library:

Just add an if to the ready:layout event of the date field so that it looks like that:

if ($ == null) then
   $.rawValue = num2date(date(), DateFmt(1))
endif

That should prevent the repeated prefilling once a date has been set.

In JavaScript

if (this.rawValue == null) {

   your code

}

Avatar

Level 3

Thanks - I have this in the layout:ready event of the date field (in FormCalc):

 

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

 

When I try and submit the form however, I get an error message:

 

"The value you entered for Current date: is invalid. To ignore validations for Current date; click Ignore."

 

If I click ignore, it will submit the form, but the auto-calculated date field doesn't lock and just updates again whenever the form is opened.

 

 

Avatar

Employee

Check your locale and date format in the patterns. Apparently the "date string" of the prefill does not match what the validation pattern expects.

Avatar

Level 3

Hi Kosta,

Thanks again for your input. I'm still struggling to get the date field to lock.

Regarding the code you told me to put into the layout:ready field - do I just copy your code and paste it in? I don't need to change anything such as DateFmt? Should that code all be in FormCalc rather than JavaScript?

When I change the DateFmt and have the following code in layout:ready with language set to FormCalc:

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

then the form fills in OK and I don't get any error message, but after submitting the form it doesn't lock the field, with the date updating each time I open the form.

When I just copy and paste it in, with the option set to formcalc, I can fill in the form OK and don't get a validation error message, but the field is not locked after submitting the form, and updates each time I open that form.

Locale for this field is set to "default locale" which is "English (USA)".

Thanks!

 

Avatar

Employee

Check out my sample. The way I use this form is to open it in Reader, today`s date is prefilled. For testing I set it manually to yesterday and then Save As another file (emailing2.pdf). When I open emailing2.pdf I get yesterday's date - which is expected result.

https://documentcloud.adobe.com/link/review?uri=urn:aaid:scds:US:e600abc1-348d-47c7-b832-a71183a1a5a...

Avatar

Level 3

Thanks for that Kosta. I'm sorry, I've been an idiot. I've been working on the current date field, but testing on the current time field, for which I have not entered any code! Would you be able to advise on what I should put in the "current time" field to get it to lock that also?

Avatar

Employee

Use a DateTime field, set the patterns to time{HH:MM:SS} and Binding - Data Format to Time and the following script

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

Avatar

Level 3

Hi Kosta, with your help I managed to get the time to lock. I'm still working on the date but should be able to get there.

Regarding having the Forename & Surname initials in the email subject field, I have the following script in the presubmit, as javascript;

var sMailUrl=this.resolveNode("#event").submit.target;

this.resolveNode("#event").submit.target=sMailUrl + "?subject=Some Text "+form1.Page1subform.PatientSubform.Forname.rawValue+" "+form1.Page1subform.PatientSubform.Surname.rawValue + "(" + form1.Page1subform.PatientSubform.Forname.rawValue.substr(0,1) + form1.Page1subform.PatientSubform.Surname.rawValue.substr(0,1) + ")";

However, I am still getting generic text in the email subject field and not the "some text" and initials like I should. Do I need to change anything with this script? Add an email address or anything? Thanks!