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
Solved! Go to Solution.
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)?
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)?
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
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.
Hello,
Where exactly do we add the code you posted in the comment above?
Thanks!
Where exactly do we add the code you posted in the comment above?
Thanks!
Anywhere after the <script> that loads forms2.min.js (the Forms 2.0 library).