Add Form Submission Date/Time Stamp | Community
Skip to main content
Level 4
July 24, 2024
Question

Add Form Submission Date/Time Stamp

  • July 24, 2024
  • 2 replies
  • 4499 views

I am trying to add Javascript to a Marketo LP using a Marketo form that adds a date/time stamp to the submission. I have created a new field in Marketo named Last Form Submission Date (lastFormSubmissionDate) and am adding the field to the form. Then on the Marketo page I am adding this code to the Custom Head:

<script> MktoForms2.whenReady(function(mktoForm){ mktoForm.onSubmit(function(mktoForm){ mktoForm.addHiddenFields({ lastFormSubmissionDate : new Date().toISOString() }); }); }); </script>

It is not populating the field though, so wondering what I am doing wrong.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Level 4
July 24, 2024

Hey @kenmckown - I think you might be making this more complicated than it needs to be!

 

Why don't you use a system token in a change data value? 

 

From Experience League:

 

The {{system.dateTime}} token will render the current date and time at runtime like so: 2013-08-08 16:36:13

Works in:

You can use a Change Data Value flowstep to change the data value of your 'Last Form Submission Date' to {{system.DateTime}}! 

kenmckownAuthor
Level 4
July 24, 2024

This was actually my first thought, but we wanted to make sure it was written at the time of submission so we can use it to route in Dynamic Chat, so it needs to be real time as opposed to a program, which could have a little delay.

 

Does that make sense?

Level 4
July 24, 2024

@kenmckownThere shouldn't be a delay unless you include a wait step, but I see what you mean with Dynamic Chat. Do you mind sharing your use case in full? That would probably help more. 

SanfordWhiteman
Level 10
July 24, 2024

The specific reason your code doesn’t work is it has a dependency on the global MktoForms2 object and you’re loading it in the <head>, while the Forms 2.0 library loads somewhere in the body.

 

Move the code just before the closing </body> tag and it’ll work.

 

As for doing this on the form vs. in a Smart Campaign, I like doing it on the form because it will really capture the form submission time.

kenmckownAuthor
Level 4
July 24, 2024

Would I have to add that to the LP Template? There is not a way to edit the code of a LP itself correct?