Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pass the GET parameters / url variables / query string, from a hubspot form to your redirect/thank-you page. Apparently, to do this now, you have to manually define the redirect url in the script. It's not exposed in hsContext anymore.
/**
* Append the form data from a HubSpot form automatically
* to the redirect URL query parameters. These values can
* then be used on the form to modify the user experience
* of the Thank You page
*
* LICENSE
* Form redirect
* Written in 2015 by Mike Axiak <maxiak@hubspot.com>
* Updated in 2016 by Seth Meranda <seth.meranda@cune.edu>
* Updated in 2017 by Ray Aguilar <flexgrip@gmail.com>
* To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
* You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
function appendFormData (form) {
/*
* Define your redirect URL here. (Yeah, it's
* stupid... But Hubspot apparently doesn't
* expose the redirect url on embedded forms
* anymore. Or at least I can't find it...)
*/
var redirect = "https://your-url-goes-here.com";
var appendFields = function (url, values) {
var data = {};
$.each(values, function (i, item) {
if (item.name !== "hs_context") {
data[item.name] = item.value;
}
});
if (url.match(/\?/)) {
return url + "&" + $.param(data);
} else {
return url + "?" + $.param(data);
}
};
var $hsContext = form.find("input[name='hs_context']");
var hsContext = JSON.parse($hsContext.val());
hsContext.redirectUrl = appendFields(redirect, form.serializeArray());
$hsContext.val(JSON.stringify(hsContext));
}
/**
* add this to the embed form onFormSubmit callback
* http://developers.hubspot.com/docs/methods/forms/advanced_form_options
**/
onFormSubmit : function($form, ctx) {
appendFormData($form);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.