Random Generated Unique ID Upon Form Submit | Community
Skip to main content
Michelle_LaVer1
Level 2
March 25, 2021
Solved

Random Generated Unique ID Upon Form Submit

  • March 25, 2021
  • 1 reply
  • 4406 views

Hello,

 

We are looking to generate a random ID value when a Marketo form is submitted. We would make it a hidden form field that we'd block from being overwritten if there is an existing value. Has anyone done this and if so how?

 

Thanks,

Michelle

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

What are you using this for, may I ask?

 

In any case, you can generate a UUID.  Here the Marketo field being populated is called FormSubmissionID.  You would swap that with the SOAP name of the field in your instance:

 

(function(){ /** * @preserve contains SO @broofa's UUID polyfill (https://stackoverflow.com/questions/105034/) * @author https://stackoverflow.com/users/109538/broofa * @license CC-BY-SA * */ function uuidv4() { var crypto = window.crypto || window.msCrypto; return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); } MktoForms2.whenReady(function(mktoForm){ mktoForm.addHiddenFields({ FormSubmissionID : uuidv4() }); }); })();

 

 

Also, this is adding the UUID when the form is displayed, rather than just before it's submitted. Is there a specific reason you want it added just before submission (since it's globally unique anyway)?

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
March 25, 2021

What are you using this for, may I ask?

 

In any case, you can generate a UUID.  Here the Marketo field being populated is called FormSubmissionID.  You would swap that with the SOAP name of the field in your instance:

 

(function(){ /** * @preserve contains SO @broofa's UUID polyfill (https://stackoverflow.com/questions/105034/) * @author https://stackoverflow.com/users/109538/broofa * @license CC-BY-SA * */ function uuidv4() { var crypto = window.crypto || window.msCrypto; return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); } MktoForms2.whenReady(function(mktoForm){ mktoForm.addHiddenFields({ FormSubmissionID : uuidv4() }); }); })();

 

 

Also, this is adding the UUID when the form is displayed, rather than just before it's submitted. Is there a specific reason you want it added just before submission (since it's globally unique anyway)?

Michelle_LaVer1
Level 2
March 26, 2021

Thanks for the solution. Looking to pass a unique ID value when the form is submitted that we can pass to engineering when a new trial account is requested via our form submit.

 

Thanks,

Michelle

SanfordWhiteman
Level 10
March 26, 2021

OK, then there's no reason to not generate the ID when the form is ready. So the code above is fine.

 

I do wonder how you're planning to interlock the form submission ID with the other fields in the form, though. Technically the only place to see a discrete form payload (all fields submitted at the same time) is in the Activity Log.