Non-hubspot forms working with

I use Hubspot on my website, and Hubspot has their “non hubspot forms” where they use tracking code to pick up forms.

<!-- Start of HubSpot Embed Code -->

<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/8070487.js"></script>

<!-- End of HubSpot Embed Code -->

However on one of my pages with WCFM it is not picking up the form. It picks up login forms, checkout forms, etc.

Hi @BWhittle!

HubSpot ignores certain forms if they contain sensitive fields. For example, forms with any creditcard information will be ignored. If you check the source code of collectedform.js

you will see that they ignore forms with a type, name or value that contains “credit card”, “card number”, “expiration”, “expiry”, “ccv”, “cvc”, “cvv”, “secure code”, “mastercard”, “american express”, “amex”.

If I read the source code correctly, they also ignore forms that contain a password field, they check for the name, attribute and type as well.

So this form is not collected because it contains an input with the password type.

I think you can fix this by creating a 2 step form, first collect the necessary details and use another form to set the password.

Another option is to use the API to collect form submissions instead.

Hi there,

Thank you for your aswer. How come non-Hubspot forms work on my login pages that have a password?

@BWhittle That is a good question. I suppose collectedforms.js does retrieve form data with password inputs.

So lets analyze some differences between the 2 forms.

So the first two forms are native woocommerce forms right? And the second form seems to be created with a membership plugin for woocommerce correct?

If I check the form you are having issues with, there are no network requests triggered by HubSpot either.

If I try the register form on my-account, the form is send by, the https://forms.hsforms.com/embed/v3/counters.gif?key=collected-forms-embed-js-submit-event&count=1 is called to collect the form.

So it might be the way the first form is send, or something in your form is blocking the form to be collected by HubSpot.

We have an woocommerce form as well, and we use a custom PHP script to send the form submissions to HubSpot instead. That could be your solution if you are up for some custom work.

Thanks so much for your response! Can you provide that PHP script?

@BWhittle
It is an older script, the API has changed since we created it, but it still works.

class HubspotAPI {

 // Function to send lead to Hubspot
 public function sendLead($post) {
 // Default settings
 $baseURL = 'https://forms.hubspot.com/uploads/form/v2/';
 // Portal ID of client
 $portalId = 'xxxxx';

 // Hubspot Form ID (grabbed from URL)
 $hubspot_form = '';
 if (isset($post['hubspot_form'])) {
 $hubspot_form = $post['hubspot_form'];
 } else {
 return 'No endpoint set!';
 }

 // if (!isset($post['email'])) {
 // return 'Important information is missing';
 // }

 $params = '';

 // Loop through all post values and build URL params, example: FirstName=Teun&LastName=Rutten
 foreach($post as $key => $value) {
 if ( ! empty( $value ) ) {
 $name = $key;
 $params = $params . $name . '=' . urlencode($value) . "&";
 }
 }

 $hubspotutk = isset($_COOKIE['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' => $post['url'],
 'pageName' => isset($post['page']) ? $post['page'] : ''
 );
 $hs_context_json = json_encode($hs_context);
 $params = $params . '&hs_context=' . urlencode($hs_context_json);

 // Prepare URL
 $endpoint = $baseURL . $portalId . '/' . $hubspot_form;

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
 curl_setopt($ch, CURLOPT_URL, $endpoint);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type: application/x-www-form-urlencoded'
 ));
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $response = curl_exec($ch); //Log the response from HubSpot as needed.
 $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
 curl_close($ch);
 return $response . ' ' . $status_code;
 }
}

We created the above class, which can be called in the PHP file where you are sending your form:

$sendHubspot = new HubspotAPI();
$sendHubspot->sendLead($_POST);

You have to pass it the URL, page name and the ‘hubspot_form’ (Form ID) through the post object, which could be achieved by setting those as hidden fields, are setting it through the code.

Important note, if the name of your input of your form matches a HubSpot contact property, the value will be stored on the contact