I’m using the HubSpot forms API to send contact data from my website. Everything works fine but there’s an annoying issue. Each time I submit data through the API, HubSpot creates a new form automatically in the Marketing section. These forms get names like #form_abc123xyz and they’re marked as “non-HubSpot forms”.
The system explanation says these are HTML forms from external websites that get tracked automatically. The problem is my data gets recorded twice - once in my actual form that I created in HubSpot, and once in these auto-created forms.
Here’s my implementation:
// Configuration settings
define('CRM_PORTAL_ID', getenv('crm_portal_id'));
define('CRM_FORM_GUID', getenv('crm_form_guid'));
define('CRM_API_URL', "https://forms.hubspot.com/uploads/form/v2/".CRM_PORTAL_ID."/{guid}");
// Form submission handler
function submit_to_crm($current_url, $page_title, $api_endpoint, $form_data) {
$context_data = array(
'ipAddress' => $_SERVER['REMOTE_ADDR'],
'pageUrl' => $current_url,
'pageName' => $page_title,
);
if (isset($_COOKIE['hubspotutk'])) {
$context_data['hutk'] = $_COOKIE['hubspotutk'];
}
$form_data['hs_context'] = $context_data;
$post_string = "";
foreach ($form_data as $field => $val) {
if (is_string($val)) {
$val = urlencode($val);
} else if (is_array($val)) {
$val = json_encode($val);
}
$post_string .= $field."=".$val."&";
}
$post_string = rtrim($post_string, "&");
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
// Usage example
$api_response = submit_to_crm(
"https://mysite.com/contact-us/",
"Contact Us Page",
str_replace("{guid}", CRM_FORM_GUID, CRM_API_URL),
array(
"firstname" => $user_data["first_name"],
"lastname" => $user_data["last_name"],
"email" => $user_data["email_address"],
"phone" => $user_data["phone_number"],
"message" => $user_data["inquiry"]
)
);
Is there a way to prevent this automatic form creation? My forms list is getting cluttered with these generated entries that I have to manually delete. The original form I created is organized in a folder while these auto-generated ones appear at the root level.