我正在 Instapage 上构建一个网站,主页上有一个包含两个字段的表单:姓名和电子邮件 + 复选框。 我正在转发 URL 参数中的详细信息:
?name=Example&[email protected]&heckbox=yes
我想获取姓名、电子邮件和复选框值并将其作为文本放入表单中。
//ClickDimensions Lab Pre-Fill Forms From URL Parameters
//For more information see http://blog.clickdimensions.com/2014/06/pre-fill-forms-from-links-or-webpages.html
//NOTE: This code is provided as a sample only for the purposes of illustration.
//This function gets the parameters from the URL and sets variables for the fields to be pre-filled
function getParm(name)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
//set variables for each of the fields you wish to pre-file
//reference them by the ID you found for the field when viewing the source
NameField = document.getElementById("field-b268d8dd6e388aec6d626ce6f054ccda-0");
EmailField = document.getElementById("field-b268d8dd6e388aec6d626ce6f054ccda-1");
CheckboxField = document.getElementById("hidden-field-b268d8dd6e388aec6d626ce6f054ccda-2-0");
if(results == null)
return "";
else
return results[1];
}
//This function executes the function above and set the values in the fields
window.onload=function execParm() {
var fieldName = getParm('Name');
var fieldEmaiil = getParm('Email');
var fieldCheckbox = getParm('Checkbox');
NameField.value = fieldName;
EmailField.value = fieldEmaiil;
CheckboxField.value = fieldCheckbox;
}
我之前一直在使用 webflow/jotform,这个过程更容易,并且在他们的论坛上进行了解释,而 instapage 则不清楚。
有人可以在这里给我提示吗? 哈x