Displaying unique form on dynamic page from dataset

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 :confused:

  1. Fetching the HTML code for that form from the dataset, and inserting it into the iFrame

  2. 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:

  1. How can I get this form to display on my site?

  2. 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 :frowning:

You will find that the code you have been given probably needs to be added as a custom tool in Tracking and Analytics.
https://support.wix.com/en/article/embedding-custom-code-to-your-site

Hi,

I have already added this code to the header. Still doesn’t work. Any idea why?

You don’t put it in the header on your page, you put it in the head section of the new tool in Tracking and Analytics with the other part in an html iframe on your page.

@givemeawhisky Hi. Sorry, I mistyped. This is what I have done, but it doesn’t work.

If you need more support with this then you need to be going back to MailerLite and asking their own support as Wix does not provide support for third party code.

Plus, if you are using them for emails etc, then I would suggest that you authenticate your domain with them too.
https://mailerlite.supporthero.io/article/show/62599-how-to-authenticate-domain-with-wix

Your best option would be to use their own REST API.
https://help.mailerlite.com/article/show/29283-does-mailerlite-offer-an-api
https://developers.mailerlite.com/docs

Then you can use Wix HTTP Functions / Wix Fetch to exposes your site to it.
https://www.wix.com/corvid/reference/wix-http-functions.html
https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions
https://www.wix.com/corvid/reference/wix-fetch.html
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api

You can see an example here about it that you can open up in your own Wix Editor.
https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-myapi-and-myapiclient