Hi,
So I’m not a coder by any stretch of the imagination, so please excuse any junior errors…
But what I’m trying to do is display a form from MailerLite on one of my dynamic pages. I have a separate form for each page. The only way I’ve currently found to display forms from MailerLite is using their HTML embed option. The javascript option seems much simpler, but it won’t work for some reason.
Logically, it seems like there are 2 options, but I cannot figure out how to do either
-
Fetching the HTML code for that form from the dataset, and inserting it into the iFrame
-
Each form has the same code, except for the form ID, which is fetched from the dataset and inserted into the iFrame.
Here is the javascript code that MailerLite says to put in the header of all pages on my site:
<script>
(function(m,a,i,l,e,r){ m['MailerLiteObject']=e;function f(){
var c={ a:arguments,q:[]};var r=this.push(c);return "number"!=typeof r?r:f.bind(c.q);}
f.q=f.q|
[];m[e]=m[e]||f.bind(f.q);m[e].q=m[e].q||f.q;r=a.createElement(i);
var _=a.getElementsByTagName(i)[0];r.async=1;r.src=l+'?v'+(~~(new Date().getTime()/1000000));
_.parentNode.insertBefore(r,_);})(window, document, 'script', 'https://static.mailerlite.com/js/universal.js', 'ml');
var ml_account = ml('accounts', '1884646', 'l1d7c1w7h5', 'load');
</script>
And the code for an example form:
<div class="ml-form-embed"
data-account="1884646:l1d7c1w7h5"
data-form="1778694:w1k7m7">
</div>
From what I can tell, the only thing that changes in the second piece of code for a different form is the data-form string (in bold).
So my questions are:
-
How can I get this form to display on my site?
-
How can I replace the “data-form” string with a field from the dataset for each dynamic page?
Massive thanks to anyone who can help out. Been trying to figure this out for days now and I’m getting nowhere