Trying to swap out a legacy Marketo form for a new Hubspot one


Trying to swap out a legacy Marketo form for a new Hubspot one, but not sure if/how within the Hubspot API this might be possible.

The legacy code uses:

    MktoForms2.loadForm("//", "445-ZDB-645", 1935, function(form){
        form.onSuccess(function(values, followUpUrl){
            var customFollowUpUrl = '<?php echo $thank_you_lander_permalink; ?>';
            if (customFollowUpUrl) {
                var calc = window.NasuniStorageCostCalculator;
                var data = {
                    forName: values.FirstName + " " + values.LastName,
                    forCompany: values.Company,
                    savings: parseInt(jQuery('.final-calculation__amount--total > .value').html().replace(/,/g , "")),
                    percentage: parseInt(jQuery('.final-calculation__amount--percent > .value').html()),
                    traditional: calc.getTotal('traditional'),
                    nasuni: calc.getTotal('nasuni'),
                    r2c1: '17872.33',
                    r2c2: calc.getTotal('nasuni') /,
                    r3c1: calc.getCapacityPricing('traditional',,
                    r3c2: calc.getCapacityPricing('nasuni',,
                    r4c1: calc.getMobileUsersPricing('traditional', /,
                    r4c2: '-1',
                    r5c2: '-1',
                    r6c1: calc.getMobileUsersPricing('traditional',,
                    r6c2: '-1',
                    r7c1: calc.getRemoteLocationsPricing(, 'traditional',,
                    r7c2: calc.getRemoteLocationsPricing(, 'nasuni',,
                window.location = customFollowUpUrl + '?' + jQuery.param(data);
            return false;

As you can see, Marketo uses the “MktoForms2.loadForm” function to collect both variables from the form as well as variables from the page (window.) and passes them into the redirect URL once the form is submitted.

Can anyone advise how this might be achieved with a Hubspot form?


@nasunibrett This is possible using the onFormSubmit callback method:

It would look something like this:

    portalId: 'XXXXXX',
    inlineMessage: 'inline message goes here',
    onFormSubmit: function( $form ) {
        var customFollowUpUrl = '<?php echo $thank_you_lander_permalink; ?>';
        // You can access global variables here (e.g:
        // $form is a jQuery object of the form that was submitted - so you can get the field data in multiple ways.
        setTimeout( function(){ // Set timeout might not be necessary - unless you want to make sure your tracking code fires if doing so...
            window.location = customFollowUpUrl + '?' + jQuery.param( data );
        }, 500 );