Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Hidden Value Field - Getting the date the user fills a form

Avatar

Level 3

Hello guys, how are you?

So, I need to get the date the user fills a form on my site as an user generated content along with the form fields everytime a user fills this form. I'm using the store content action on my form.

To do this, I've copied the foundation hidden value field and added some custom code:

Date today = new Date(); int dd = today.getDate(); int mm = today.getMonth()+1; int yyyy = today.getYear(); String strDd = ""; String strMm = ""; String strYyyy = ""; if(dd<10) { strDd='0'+ Integer.toString(dd); } if(mm<10) { strMm='0'+ Integer.toString(mm); } String strToday = Integer.toString(dd) +'/'+ Integer.toString(mm) +'/'+ Integer.toString(yyyy); Node node = resource.adaptTo(Node.class); node.setProperty("defaultValue", strToday); node.setProperty("name", "Data"); node.getSession().save();

Doing this I do get a date on the defaultValue of my hidden value component content node and in the user generated data, but always the same date (the date I've created and dropped the component in the form). How do I do to get a new date everyday? Everytime a user fills the form, the component should get the current date. Is this possible changing this code or in some other way?

Edit: Working with AEM 6.0, SP3 (I am, not the component.)

 

Thanks very much.

Matheus Barreto.

6 Replies

Avatar

Level 10

You can change the code in a form script to get the current date using JavaScript. 

Avatar

Level 3
Hi, how are you? It's not possible to do with custom script in the hidden data component as I've tried? If not, care to elaborate how would I do this on the form component code so that when a visitor submit a form, I'll get the date as part of the user generated content? Thanks very much.

Avatar

Administrator

Hi 

Moving this thread to AEM "Forms" topic so to have better contextual experts have a look at this.

~kautuk



Kautuk Sahni

Avatar

Level 3

Matheus, looking at the above code, can you confirm whether or not you're trying to populate an Adaptive Form or is this a Site form?

Avatar

Level 3

Hi, how are you? Site form, the native form component, not adaptative one. Any tip or trick? :)

Thanks!

Avatar

Level 3

Still waiting for some help. Is there any other channel where I can try to find help regarding this topic?