Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
@HubSpotHanevold
HubSpotHanevold / sample.php
Created April 16, 2025 16:33
Sample PHP Curl Forms Submit API
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.hsforms.com/submissions/v3/integration/submit/portalId/formGuid',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
@HubSpotHanevold
HubSpotHanevold / script.js
Last active December 3, 2024 20:00
Validate additional property as email only
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
const emailInput = document.querySelector('input[name="2-8330456/tour_contact_email"]');
emailInput.addEventListener("input", function() {
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const parentDiv = emailInput.closest('.input');
let messageDiv = parentDiv.querySelector('.email-error');
@HubSpotHanevold
HubSpotHanevold / script.php
Last active December 3, 2024 16:36
A php script to replicate HubSpot properties created on a standard object and add to a custom object. Only creates non-HubSpot default properties on the new object.
<?php
// PHP SCRIPT TO MOVE PROPERTIES FROM A STANDARD OBJECT TO A CUSOTM OBJECT
// READ ME
// MODIFY THESE VARIABLES BELOW AS YOU SEE FIT (LINES 8-10)
// ALSO MODIFY THE GROUP NAME MAPPINGS BELOW (LINES 53-56)
$authToken = 'ADD_YOUR_TOKEN_HERE';
$standardObject = 'contacts';
$customObjectInternalName = '2-37668321';
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 13, 2024 16:47
Push URL of page to a form property
<script>
document.addEventListener("DOMContentLoaded", function() {
// Wait for the form to load
setTimeout(function() {
var urlInput = document.querySelector('input[name="url_of_page"]');
if (urlInput) {
console.log('url_of_page input exists');
urlInput.value = window.location.href;
}
},1000); // Adjust the delay if needed
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 7, 2024 17:15
Melissa Data Integration
<script>
window.onload = function () {
// Function to poll for the existence of the input field
function waitForElement(selector, callback) {
const inputField = document.getElementsByName(selector)[0];
if (inputField) {
callback(inputField);
} else {
setTimeout(function () {
waitForElement(selector, callback);
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 7, 2024 00:46
Using typeahead on a HubSpot form
// include the following scripts that can be found here https://select2.org/getting-started/installation
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
// in the below, we listen for the form to load, then switch out the standard select element (by name) with a select2 element
<script>
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
// Initialize Select2 on the specified select element - update with the internal name of the property where it says internal_select_name
const selectElement = $('select[name=internal_select_name]').select2();
import requests
url = "api.hubspot.com/events/v3/events/?objectType=contact&objectId=52054635672"
payload = ""
headers = {
'Authorization': '••••••'
}
response = requests.request("GET", url, headers=headers, data=payload)
exports.main = async (event, callback) => {
var phone = event.inputFields['phone'];
console.log("Input Phone: ", phone)
const outputFields = {
valid: false,
validation_message: "",
phone: ""
}
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
const emailInput = document.querySelector('input[name="firstname"]');
emailInput.addEventListener("input", function() {
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const parentDiv = emailInput.closest('.input');
let messageDiv = parentDiv.querySelector('.email-error');
@HubSpotHanevold
HubSpotHanevold / check api limit.js
Created August 21, 2024 16:51
A simple custom coded action to check API limits in workflows.
const axios = require('axios');
exports.main = async (event, callback) => {
const auth = 'Bearer ' + process.env.CHANGE_THIS_VALUE_TO_MATCH_YOUR_SECRET_NAME;
const email = event.inputFields['email'];
let data = JSON.stringify({
"filters": [
{