• Resolved simonfunk

    (@simonfunk)


    After the update to the latest version, i get a JS error:

    hbspt.forms.create is not a function

    The issue under the class-pagehooks.php file under add_form_management_script(). The hbspt.enqueueForm closes before the Object.defineProperty is called.

    In the runtime, the create function is undefined.

    Here is our custom code:

    const $ = window.jQuery,
        portalId = window.App ? window.App.hubspot_portal_id : false;
    
    export default function () {
        if (!portalId) {
            return;
        }
    
        $('.hubspot-form').each(function (index) {
            const $this = $(this),
                id = 'hubspot-form-' + index;
            $(this).attr('id', id);
            hbspt.forms.create({
                css: '',
                target: '#' + id,
                formId: $this.data('formId'),
                portalId: portalId,
                cssClass: 'hubspot-form',
            });
    
        });
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter simonfunk

    (@simonfunk)

    Here is the solution:
    https://ww.wp.xz.cn/support/topic/new-update-for-hubspot-breaks-form/#post-13632819

    Can you please integrate it so it is save for update?

    Hello @simonfunk.

    Thank you very much for sending us the code. We are currently studying the issue and we will let you know here once we release the fix.

    Kind regards,
    Alvaro

    Hello @simonfunk,

    After studying the issue, we have been able to find the root cause of the issue. This is due to the forms handler script src='https://js.hsforms.net/forms/v2.js' is executed, in your code before the snippet

    Object.defineProperty(window.hbspt.forms, 'create', {
        configurable: true,
        get: function() {
            return hbspt._wpCreateForm;
        },
        set: function(value) {
           hbspt._wpCreateForm = value;
           while (hbspt._wpFormsQueue.length) {
               var formDef = hbspt._wpFormsQueue.shift();
    	   if (!document.currentScript) {
                  var formScriptId = '<?php echo esc_html( AssetsManager::FORMS_SCRIPT ); ?>-js';
                  hubspot.utils.currentScript = document.getElementsById(formScriptId);
    	   }
    	   hbspt._wpCreateForm.call(hbspt.forms, formDef);
           }
        },
    });

    This causes the set to not executed. Can you confirm that this is also your case?

    We will release a fix for this shortly.

    Kind regards,
    Alvaro

    Hello @simonfunk,

    We just released a new version that we trust should fix your problem without needing the extra snippet

    Thread Starter simonfunk

    (@simonfunk)

    Great, thanks

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Update for Hubspot breaks programmatic form’ is closed to new replies.