Form API - POST resulting in unwanted form being added to form list with duplicate entries


Sending a form submission to hubspot via API is resulting in the following expected behavior:

Form submission is received by hubspot, hubspot returns success 204.
Form submission data is associated with the expected form (re: specified form id).
Form field data is associated with the expected fields in hubspot.

All looks good. EXCEPT, in addition to appending the form submission to the desired form, hubspot is also creating a new non-hubspot form and duplicating the submission to it as well. Very odd. The new unwanted form that is created is named after the id and class of the form (HTML).

Here is how the form submission is being handled on the front-end:

<form action="<?php echo get_template_directory_uri() . '/methods/hubspot/hubspot.php' ?>" enctype="multipart/form-data" method="POST" class="form c-white" id="form_contact-form">

And here is how it is being handled on the back-end:

function fnctn_hubspot_request() {
	// Get Field IDs
	$fieldIds = array(
		'whyContact' => FrmField::get_id_by_key('why-contact'),
		'firstName' => FrmField::get_id_by_key('first-name'),
		'lastName' => FrmField::get_id_by_key('last-name'),
		'email' => FrmField::get_id_by_key('email'),
		'country' => FrmField::get_id_by_key('country'),
		'jobTitle' => FrmField::get_id_by_key('job-title'),
		'companyName' => FrmField::get_id_by_key('company-name'),
		'tellUsWhy' => FrmField::get_id_by_key('tell-us-why'),

	// Collect the field values, associated with the keys
	$fieldMeta = $_POST['item_meta'];

	$hubspotutk      = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
	$ip_addr         = $_SERVER['REMOTE_ADDR']; //IP address too.
	$hs_context      = array(
	    'hutk' => $hubspotutk,
	    'ipAddress' => $ip_addr,
	    'pageUrl' => $_SERVER['HTTP_REFERER'],
	    'pageName' => ''
	$hs_context_json = json_encode($hs_context);

	//Need to populate these variable with values from the form.
	$postData = array(
		"firstname" => $fieldMeta[$fieldIds['firstName']],
	    "lastname" => $fieldMeta[$fieldIds['lastName']],
	    "email" => $fieldMeta[$fieldIds['email']],
	    "country" => $fieldMeta[$fieldIds['country']], 
	    "jobtitle" => $fieldMeta[$fieldIds['jobTitle']],
	    "company" => $fieldMeta[$fieldIds['companyName']],
	    "why_are_you_contacting_us" => $fieldMeta[$fieldIds['whyContact']], 
	    "please_describe_your_interest_in_working_with_us_" => $fieldMeta[$fieldIds['tellUsWhy']],

	//Build a friendly parameter string from all of this data, to be cUrl
	$paramString = '?'.http_build_query($postData,'','&').'&hs_context='.urlencode($hs_context_json);

	//replace the values in this URL with your portal ID and your form GUID. Removed IDs for this post.
	$endpoint = ''; 
	$ch = curl_init($endpoint);                                                                      
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
	curl_setopt($ch, CURLOPT_POSTFIELDS, $paramString);                                                                  
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
	    'Content-Type: application/x-www-form-urlencoded',                                                                                
	    'Content-Length: ' . strlen($paramString))                                                                       
	$result = curl_exec($ch);

	// Redirect to this page.
   header("Location: " . $_SERVER['HTTP_REFERER']);


Okay, I am going to leave this post here in the event that another needs assistance. Those "unwanted" forms are actually created via the "non-hubspot form" feature in hubspot. That is, it is not an issue. See below: .


Welcome, @fnctn

I'm glad to see that you found your solution so quickly!

Yes, this behavior is related to the non-HubSpot form tool. For others reading this post, if you don't want such forms created in your account, you can disable the tool in Settings > Marketing > Forms > Non-HubSpot Forms.