/** * 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 * Updated in 2016 by Seth Meranda * Updated in 2017 by Ray Aguilar * 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 . */ 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); }