SOLVED

Re: Update form prefill when a user changes

Go to solution
Anonymous
Not applicable

Update form prefill when a user changes

Hi,

We use a custom page (Marketo landing page with form) to let people manage their email preferences and unsubscribe.  We recently came across the issue where a user unsubscribed from our emails, we then sent an email to them but using a different email address.  Then they clicked on that email to unsubscribe however it is pre-populating/pre-filling the original email address which it has rememberd through the Marketo Cookie.  This means that unless they update the page manually or delete their cookies, they will not be able to unsubscribe from the second email address.

Is there a way to make form pre-fill's update if a user clicks through/visits the page with a new email address/one that is different from the original cookie, has anyone else encountered this?  The only solution I can currently see is to go back to a one click unsubscribe as this is a potentially huge issue given the number of people who use multiple email addresses.

Thanks,

Simon 
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Update form prefill when a user changes

To completely reassociate the form with a new lead identified by email requires 2 steps.

1. Delete cookies and reload the page as to create a fresh form view.
2. Set the email address and reload the page again to get the form prefilled.

This code (in a landing page HTML widget) will set you on the right track:

<script>
MktoForms2.whenReady(function (form){

var parentDomain = location.host.split('.').slice(1).join('.');
var requestEmail, requestSubmit;

try {
    requestEmail = document.location.search.match(/(?:^|\?|&)email=(.*?)(?:&|$)/i)[1];
} catch (e) {}

try {
    requestSubmit = document.location.search.match(/(?:^|\?|&)submit=(.*?)(?:&|$)/i)[1];
} catch (e) {}

if ( requestEmail && requestSubmit == 'true' ) {

// set values to override email and  submit form
form.setValues({ Email: requestEmail });
form.submit();

} else if ( requestEmail) {

// erase tracking cookies and reload
document.cookie="_mkto_trk=" +
    ";expires="+new Date(0).toGMTString() +
    ";domain="+parentDomain +
    ";path=/";

document.location.search += '&submit=true';

}

});
</script>
 

View solution in original post

8 REPLIES 8
SanfordWhiteman
Level 10 - Community Moderator

Re: Update form prefill when a user changes

One way to combat this is to embed the e-mail address in the link.  Then you can compare the email address that is prefilled with the "current" email address and change the field value accordingly.

It's not an easy problem to solve, though, because it isn't really a problem but more like the way we expect form prefill to work, right?
Anonymous
Not applicable

Re: Update form prefill when a user changes

Hi Sanford,

I would not have thought so, in my opinion if we know who you are, great pre-fill the form.  If you are trying to visit a form and the identity (i.e. email address) you are visiting from is different, we should query this (and ideally give a choice). After all, people will change email address, change jobs but not necessarily change computers or delete cookies.

But thanks for your suggesting, I know very little about code, is there anywhere you could point me to help with the idea of using an email address embedded in a link?

Simon 
Anonymous
Not applicable

Re: Update form prefill when a user changes

Marketo FOrms 2.0 have functionality to auto populate a given field from either
'Cookie value' or 'url parameter' or 'default value' or 'Referrer'
But that is applicable only for 'Hidden' fields.
For fields which are not hidden, the default pre-fill functionality takes over. And that is I believe always from cookie value. 
Please see for information about this here,
https://community.marketo.com/MarketoArticle?id=kA050000000LH7uCAG
So I guess you will have to pass email address in the link and write some javascript to override the pre-filled value.

Hope this helps

Rajesh
 
SanfordWhiteman
Level 10 - Community Moderator

Re: Update form prefill when a user changes

@Simon When I say it's the expected behavior, I mean that if you don't supply additional info there's no way for the form to know that you have anything different/more current than the prefill info.

Here's a demo (do view-source to see how it works) with the First Name filled in via prefill by default but can be overridden in the URL if present: http://s.codepen.io/figureone/debug/ZYPYQy?#mySpecialNewName
 
Anonymous
Not applicable

Re: Update form prefill when a user changes

Hi Sanford,

Thank you very much for this, using the method in the demo works pretty well, I wonder if you could answer one more question.  The form in question pre-fills quite a few fields, do you know of the code if I was to pre-fill the email address and then "re-trigger" the form to load the other fields based on that email address?

Simon
SanfordWhiteman
Level 10 - Community Moderator

Re: Update form prefill when a user changes

I'll send a sample of this tomorrow.
SanfordWhiteman
Level 10 - Community Moderator

Re: Update form prefill when a user changes

To completely reassociate the form with a new lead identified by email requires 2 steps.

1. Delete cookies and reload the page as to create a fresh form view.
2. Set the email address and reload the page again to get the form prefilled.

This code (in a landing page HTML widget) will set you on the right track:

<script>
MktoForms2.whenReady(function (form){

var parentDomain = location.host.split('.').slice(1).join('.');
var requestEmail, requestSubmit;

try {
    requestEmail = document.location.search.match(/(?:^|\?|&)email=(.*?)(?:&|$)/i)[1];
} catch (e) {}

try {
    requestSubmit = document.location.search.match(/(?:^|\?|&)submit=(.*?)(?:&|$)/i)[1];
} catch (e) {}

if ( requestEmail && requestSubmit == 'true' ) {

// set values to override email and  submit form
form.setValues({ Email: requestEmail });
form.submit();

} else if ( requestEmail) {

// erase tracking cookies and reload
document.cookie="_mkto_trk=" +
    ";expires="+new Date(0).toGMTString() +
    ";domain="+parentDomain +
    ";path=/";

document.location.search += '&submit=true';

}

});
</script>
 
Anonymous
Not applicable

Re: Update form prefill when a user changes

Thank you very much for your help here Sanford, I am trying this out and testing it now, fingers crossed it all works.