Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Last active February 1, 2024 15:10
Show Gist options
  • Save NickDeckerDevs/e0df794e1ba6ae385906ffc333002c3d to your computer and use it in GitHub Desktop.
Save NickDeckerDevs/e0df794e1ba6ae385906ffc333002c3d to your computer and use it in GitHub Desktop.
ajax example to send html form data to hubspot
<form>
<~-- form html here -->
</form>
<script>
function onSubmit() {
const formGuid = 'xxxxxxxxxxxxx'
const portalId = 'xxxxxxx'
// need variables for hubspot token and other mandatory items to submit https://legacydocs.hubspot.com/docs/methods/forms/submit_form
$.ajax({
url: `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formGuid}`,
type: "POST",
contentType: "application/json",
data: JSON.stringify({
"fields": [{
"name": "firstname",
"value": fname,
},
{
"name": "lastname",
"value": lname,
},
{
"name": "email",
"value": mail,
},
{
"name": "condo_project_item",
"value": condoProject,
},
// more fields concontinued...
],
}),
success: function(result) {
console.log(result);
},
error: function(xhr,status,error) {
console.log(xhr);
console.log(status);
console.log(status.responseText);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment