Re: Using local tokens in forms 2.0

Anonymous
Not applicable

Re: Using local tokens in forms 2.0

No worries Greg you've been very helpful! Thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Using local tokens in forms 2.0

I'll hook you up later tonight.

SanfordWhiteman
Level 10 - Community Moderator

Re: Using local tokens in forms 2.0

There are a couple of basically equivalent approaches, but here's an easy one: http://pages.vaneckdemos.com/Form-Disclaimer-from-Token.html

The LP contains this bit of code (in an HTML block):

<script>

MktoForms2.whenReady(function(form){

  var formEl = form.getFormElem()[0],

    replaceableEls = formEl.querySelectorAll('[data-replace-with]');

  Array.prototype.forEach.call(replaceableEls, function(el) {

    replacementEl = document.querySelector('#'+el.getAttribute('data-replace-with'));

    el.parentNode.replaceChild( replacementEl, el );

    replacementEl.removeAttribute('style');

  });

});

</script>

This is the disclaimer on the LP with the token:

pastedImage_1.png

And this is the Rich Text area on the form:

pastedImage_0.png

Note the code allows you to have unlimited pairs of data-replace-with and replacement elements.

Anonymous
Not applicable

Re: Using local tokens in forms 2.0

Nice work, thank you!

Anonymous
Not applicable

Re: Using local tokens in forms 2.0

This is awesome thanks Sanford WhitemanGrégoire Michel

For the js element in html block I couldn't, create a html block since I'm using a guided template (not free-form)
so I inserted it in the template, should I put it along with the other scripts?

I tried inserting in the header, it doesn't seem to work.

Grégoire_Miche2
Level 10

Re: Using local tokens in forms 2.0

Hi Will,

Insert it in the footer. The form has to be created for the additional code to work.

-Greg

Anonymous
Not applicable

Re: Using local tokens in forms 2.0

Thanks Greg, should I include this in the footer too:
<div ID="Disclaimer" style="display:none">{{my.Disclaimer}}</div>

SanfordWhiteman
Level 10 - Community Moderator

Re: Using local tokens in forms 2.0

Will, I advise putting the disclaimer above the form.

Greg, the script needs to run after the Marketo forms library (forms2.min.js) is included, but it it doesn't have to be after the form itself. (An inline <script> that calls MktoForms.whenReady will be done before the form is injected into the page.)

Grégoire_Miche2
Level 10

Re: Using local tokens in forms 2.0

Got it. Thx

Anonymous
Not applicable

Re: Using local tokens in forms 2.0

Awesome, thanks so much works like a charm!