Add Form Submission Date/Time Stamp

kenmckown
Level 4

Add Form Submission Date/Time Stamp

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.

10 REPLIES 10
jsiebert
Level 5

Re: Add Form Submission Date/Time Stamp

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}}! 

Jack Siebert
kenmckown
Level 4

Re: Add Form Submission Date/Time Stamp

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?

jsiebert
Level 5

Re: Add Form Submission Date/Time Stamp

@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. 

Jack Siebert
kenmckown
Level 4

Re: Add Form Submission Date/Time Stamp

Sure, we will be using dynamic chat to book a meeting, which uses a conversational form that asks questions. We want to use that date stamp to route whether to send it directly to a sales rep (during business hours) or to a queue for after hours. Basically using that date and time stamp to know if it can be worked right away.

Michael_Florin
Level 10

Re: Add Form Submission Date/Time Stamp

You might as well put any date field as hidden field on your form and populate it with the system.token. Like this:

Michael_Florin_0-1721836240249.png

 

kenmckown
Level 4

Re: Add Form Submission Date/Time Stamp

I tried that, but since it is a string, it shows up like this:

kenmckown_0-1721837821424.png

 

Assume I need to make it a time/date field type?

SanfordWhiteman
Level 10 - Community Moderator

Re: Add Form Submission Date/Time Stamp

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.

kenmckown
Level 4

Re: Add Form Submission Date/Time Stamp

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

kenmckown
Level 4

Re: Add Form Submission Date/Time Stamp

It is still pulling back the value like this:

kenmckown_0-1721842463633.png