# Javascript embed form error

**URL:** <https://forum.mautic.org/t/javascript-embed-form-error/20806>\
**Category:** Mautic 4 Install/Upgrade Support\
**Created:** [September 9, 2021, 9:23pm UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806 "2021-09-09T21:23:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![techbill](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/techbill/32/8325_2.png) [@techbill](https://forum.mautic.org/u/techbill)\
**Post date:** [September 9, 2021, 9:23pm UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806/1 "2021-09-09T21:23:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![techbill](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/techbill/32/8325_2.png) [@techbill](https://forum.mautic.org/u/techbill)\
**Post date:** [September 10, 2021, 6:32pm UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806/2 "2021-09-10T18:32:37Z")

</div>

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](https://www.agwm.org/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.

---

<div class="post-metadata">

**Author:** ![vincent.fr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/vincent.fr/32/6600_2.png) [@vincent.fr](https://forum.mautic.org/u/vincent.fr)\
**Post date:** [November 13, 2022, 3:03pm UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806/3 "2022-11-13T15:03:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![techbill](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/techbill/32/8325_2.png) [@techbill](https://forum.mautic.org/u/techbill)\
**Post date:** [November 14, 2022, 2:10pm UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806/4 "2022-11-14T14:10:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vincent.fr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/vincent.fr/32/6600_2.png) [@vincent.fr](https://forum.mautic.org/u/vincent.fr)\
**Post date:** [March 2, 2023, 11:14pm UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806/5 "2023-03-02T23:14:22Z")

</div>

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)

[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)

---

<div class="post-metadata">

**Author:** ![carlosatfongo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/carlosatfongo/32/10223_2.png) [@carlosatfongo](https://forum.mautic.org/u/carlosatfongo)\
**Post date:** [August 1, 2023, 12:10am UTC](https://forum.mautic.org/t/javascript-embed-form-error/20806/6 "2023-08-01T00:10:21Z")

</div>

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