我正在寻找一种将 HubSpot 表单的数据发送到提交后重定向到的 url 的方法,以便我可以使用它在该页面上的自定义表单中自动填充字段。我尝试将所需的数据存储在 cookie 中,但没有任何运气。我还在 github 上找到了一个脚本,用于将数据附加到 redirectURL 并在我的登录页面模板代码中进行设置,但无法使其工作:
https://gist.github.com/axiak/2bf8f43d9d4a5f9c883f
/**
* 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>
* 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() {
var $ = jQuery;
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);
}
};
$(function () {
$("body").on("submit", "form.hs-form", function (e) {
var $form = $(this);
var apiUrl = $form.attr("action");
var $hsContext = $("input[name='hs_context']", $form);
var hsContext = JSON.parse($hsContext.val());
hsContext.redirectUrl = appendFields(hsContext.redirectUrl, $form.serializeArray());
$hsContext.val(JSON.stringify(hsContext));
});
});
})();