I am trying to pass the values from a HubSpot form submission to an external application using a simple script. Can anyone provide insight on the proper syntax? I am not a developer and am having some trouble with test submissions.
This basic script was applied to a different marketing automation tool before using HubSpot and it worked well. I have been adjusting the input value formats in bold with no luck.
<!--[if lte IE 8]>
<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/v2-legacy.js”></script>
<![endif]-->
<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/v2.js”></script>
<script>
hbspt.forms.create({
portalId: “000000”,
formId: “000000000000000000000000”,
onFormSubmit: function($form) {
var root = {};
var data = {};
var type = “trial”;
var attributes = {};
var userName = ‘{{ contact.email }}’;
var firstName = ‘{{contact.firstname}}’;
var lastName = ‘{{contact.lastname}}’;
var role = ‘{{ contact.title }}’;
var phone = '{{ contact.phone }}';
attributes.userName = userName;
attributes.firstName = firstName;
attributes.lastName = lastName;
attributes.role = role;
attributes.phone = phone;
data.type = type;
data.attributes = attributes;
root.data = data;var xmlhttp = new XMLHttpRequest();
var theUrl = "https://somwebsite;
xmlhttp.open(“POST”, theUrl);
xmlhttp.setRequestHeader(“Content-Type”, “application/json;charset=UTF-8”);
xmlhttp.send(JSON.stringify(root));
}
});
</script>