SOLVED

Form "Not You?" functionality

Go to solution
Rafael_Santoni1
Level 5

Re: Form "Not You?" functionality

Matthew,

I am sure it is possible even with those templates because the solution is not dependent on the template used. The Marketo cookie is "_mkto_trk" no matter what template you use and the prefilled values leverage the mktoPreFillFields array always. As long as you can destroy the cookie, it should work and clear the prefill values, you should be ok. Try putting the code below on one of your pages and visit the URL appending "?userId=guest" right after the page address. Make sure to replace the part that says "insert_your_domain_here" with your Marketo page URL domain name.

<script>

$jQuery(document).ready(function(){

if(Mkto.getUrlParam("userId") == "guest"){

         $jQuery("#_mkt_trk").val('');

         mktoPreFillFields = {};

         $jQuery(".lpeRegForm")[0].reset();

         document.cookie = '_mkto_trk=NULL; expires=-1; path=/; domain=.insert_your_domain_here.com';

     }  

});

</script>

By the way, there might be some tweaks needed for this code to work depending on the form you are using on the page.

If you have any problems implementing it, feel free to drop me a line at rafael.santoni@citrix.com

Good luck!

Rafael

SanfordWhiteman
Level 10 - Community Moderator

Re: Form "Not You?" functionality

Rafael, really shouldn't use NULL here because misleadingly implies it has a special value, but it's just a literal four-letter string "NULL" in the cookie context.  For example, if I do document.cookie='abc123=NULL ... ' I'll then have a cookie named abc123 with value "NULL".  Instead, when deleting a cookie, use an empty value to signify your intent to delete it: document.cookie='_mkto_trk=; ... ';

Also, Forms 2.0 doesn't have the #_mkt_trk field, so you don't need to clear its value, though I suppose it's harmless to use it.

Perhaps more important than the above, your code has a race condition if you try to use it with embedded forms (including when the external embed code is used on Marketo-hosted LPs).  It'll sometimes work and sometimes not.  You should use the Marketo Forms 2.0 API (the whenReady event) to ensure that the form actually exists in the DOM at the point you try to reset it.  Don't try to guess when the form is in the page, let the form itself tell you when it is ready to be filled/reset/modified.

Anonymous
Not applicable

Re: Form "Not You?" functionality

Thanks for the help and responses.

Still having some difficulty...

Here's what I got;

http://funds.clime.com.au/Clime-Outlook-for-2016.html

<script type="text/javascript">

jQuery(document).ready(function($){

    function resetMktoForm() {

        $("#_mkt_trk").val('');

        mktoPreFillFields = {};

        $(".mktoForm")[0].trigger("reset");

        document.cookie = '_mkto_trk=; expires=-1; path=/; domain=.clime.com.au';

    }

   

    if(window.location.search.indexOf("userID=guest") > -1){

        resetMktoForm();

    }

});

</script>

I'm no coder but after looking at this, I actually think the reset function is no longer defined in the version of jQuery I'm using.

It is causing this error:

TypeError: $(...)[0].reset is not a function

Old Jquery

I used to use in old land pages before Guided Templates

https://app.marketo.com/js/public/jquery-latest.min.js

New Jquery

Required for Guided Landing Pages because of Bootstrap

templates.marketo.net/template2/js/jquery-1.11.2.min.js

I have tried various things to no avail.

SanfordWhiteman
Level 10 - Community Moderator

Re: Form "Not You?" functionality

Use the code from the link in my post. 

My code never relies on jQuery (because I know native JS and because jQuery is unnecessary for something so minor).

SanfordWhiteman
Level 10 - Community Moderator

Re: Form "Not You?" functionality

Matthew, the most accurate way to do this (on any page, including a GLP) is illustrated in the script at the bottom of this page: http://pages.vaneck.com/Lab-GLP-Guest-Form.html

As noted above, you should use the Forms 2.0 API. The API has a whenReady event that tells you when the form is ready for use.  Any other attempt to time when the form is ready (and therefore ready to be reset) relies on luck.

Courtney_McAra4
Level 4

Re: Form "Not You?" functionality

Small plug for LaunchPoint Partner Marketera who can help with things like this - aka a Resource Center

Marketing Design: Web, Email, Social, & Print – Marketo LaunchPoint