Javascript embed form error

I am getting this error when trying to embed a form into my website using javascript

The form loads fine but doesn’t submit or anything. The errors appears instantly as the page loads.

What I need to do to troubleshoot this?

Thank you
Bill

Uncaught SyntaxError: Unexpected token } in JSON at position 12
at JSON.parse ()
at Object.Core.parseToObject (mautic-form.js?v1ced89cf:47)
at mautic-form.js?v1ced89cf:48
at mautic-form.js?v1ced89cf:49
mautic-form.js?v1ced89cf:8 Uncaught TypeError: Cannot read properties of undefined (reading ‘btgsubscriptionform’)
at Object.Form.prepareValidation (mautic-form.js?v1ced89cf:8)
at Object.Form.prepareForms (mautic-form.js?v1ced89cf:6)
at Object.Core.onLoad (mautic-form.js?v1ced89cf:47)
at HTMLScriptElement.script.onload (:1:491)
mautic-form.js?v1ced89cf:17 Uncaught ReferenceError: MauticFormValidations is not defined
at Object.validateForm (mautic-form.js?v1ced89cf:17)
at Object.Core.validateForm (mautic-form.js?v1ced89cf:39)
at HTMLFormElement.theForm.onsubmit (mautic-form.js?v1ced89cf:6)
validateForm @ mautic-form.js?v1ced89cf:17
Core.validateForm @ mautic-form.js?v1ced89cf:39
theForm.onsubmit @ mautic-form.js?v1ced89cf:6
mautic-form.js?v1ced89cf:8 Uncaught TypeError: Cannot read properties of undefined (reading ‘btgsubscriptionform’)
at Object.Form.prepareValidation (mautic-form.js?v1ced89cf:8)
at Object.Form.prepareForms (mautic-form.js?v1ced89cf:6)
at Object.Core.onLoad (mautic-form.js?v1ced89cf:47)
at :1:746
at generate.js?id=1&=1631213448124:11
Form.prepareValidation @ mautic-form.js?v1ced89cf:8
Form.prepareForms @ mautic-form.js?v1ced89cf:6
Core.onLoad @ mautic-form.js?v1ced89cf:47
(anonymous) @ VM57:1
(anonymous) @ generate.js?id=1&
=1631213448124:11

I just test it using the manual approach by c/p the html into my webpage and the form works as intended. I would like to try at least get the automatic javascript embed working instead.

Here the link to the test page BTG Test Form Check the JS error in browser console.

There is no error recorded on server side logs or in mautic log on this.

Hi @techbill .

Finally could you find a solution? I am seeing the same issue here in Mautic 4.4.4.

Manual copy and paste of html works fine.

However, copying the javascript command gives nothing.

I noticed that one would need to add the https: protocol infront of the path in the src=“.js?id=1”.

Any suggestion is really appreciated.

Wow … I didn’t realized that I been using Mautic for over a year now …

This post is over a year old so I am sorry I cannot remember what the solution was but you may want to check by disabling the domain restriction in the CORS Settings to see if that fixes it.

If it does fix it then you need to edit your htaccess to allow form to work across domains if you want to use CORS restriction.

I’m using version 4.4.4

For those having the same 404 error when inserting forms using script (/media/js/mautic-form.js not found): In docroot/media/js/ there is no mautic-form.js file. There is only mautic-form-src.js . I copied it to mautic-form.js (pay attention to the change the owner of this file after that).

I don’t know if there is only a difference in the file names or the content as well.

Can someone confirm whether this is the solution?

404 error is gone for now. I have not checked yet whether the form will perform correctly.

Other threads on this topic:

https://forum.mautic.org/t/why-has-defferences-media-js-mautic-form-src-js-and-app-assets-js-mautic-form-src-js/20941

https://forum.mautic.org/t/why-has-defferences-media-js-mautic-form-src-js-and-app-assets-js-mautic-form-src-js/20941

Hi, did you find out any other information? Did you end up sticking with your solution?