首页 > 解决方案 > 如何将变量字段名称放入 FormAssembly 表单上的隐藏字段中

问题描述

我们在我的组织中有两个用于潜在客户捕获的表单工具,我正在尝试创建一个电子表格,该电子表格使用相同的公式来创建 UTM 参数链接,以使用 Google Analytics 跟踪我们的营销活动。

示例公式 =SUBSTITUTE(IF(LEFT(G4,1)="[","--",CONCATENATE(G4,IF(ISERROR(FIND("?",G4,1))=TRUE,CONCATENATE("?" ),CONCATENATE("&")),IF(C4="","","estate="),IF(C4="","",C4),IF(A4="",""," &utm_campaign="),IF(A4="","",A4),"&utm_medium=",H4,"&utm_source=",D4,IF(E4<>"-",CONCATENATE("&utm_content=",E4) ,),IF(E4<>"-",CONCATENATE("",$F$2),))),"","%20")

在我们的 Pardot 页面上,我应用了https://jennamolby.com/how-to-use-utm-parameters-to-capture-lead-source-in-pardot/中概述的详细信息,并正确填充了这些隐藏字段。

我的麻烦在于 FormAssembly 表单。我可以更改上面的公式以包含 FormAssembly ID,即 tfa_199 替换 utm_medium,这可以正常工作,但是我需要我的电子表格用户知道该登录页面上正在使用哪个表单工具。有没有办法将相同的公式应用于两个表单工具,然后使用 JavaScript 填充这些隐藏字段的值?

我尝试使用 FormAssembly 标签切换 Pardot JavaScript 失败。

示例链接 https://www.tfaforms.com/4757457/?tfa_98=Test%20Estate%20X999&tfa_197=Fonzi&tfa_199=social&tfa_200=Facebook&tfa_198=Feed

// Parse the URL
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
var source = getParameterByName('utm_source');
var medium = getParameterByName('utm_medium');
var campaign = getParameterByName('utm_campaign');
var term = getParameterByName('utm_term');
var content = getParameterByName('utm_content');
var estate = getParameterByName('estate');

// Put the variable names into the hidden fields in the form"
document.querySelector("tfa_200 input").value = source;
document.querySelector("tfa_199 input").value = medium;
document.querySelector("tfa_197  input").value = campaign;
document.querySelector("tfa_201  input").value = term;
document.querySelector("tfa_201  input").value = content;
document.querySelector("tfa_196  input").value = estate;
</script> 


The ideal result is regardless of whether the form is a Pardot or FormAssembly the hidden fields populate the same using the same formula.

标签: javascript

解决方案


你有没有试过这个:

https://stackblitz.com/edit/js-hgrwkn

如果您的输入字段有 ID:

<input type="text" id="utm_source" name="tfa_200"/>

和你的隐藏字段:

<input type="hidden" id="tfa_200" name="utm_source"/>

然后:

<script>
   document.getElementById('tfa_200').value = 
        document.getElementById('utm_source').name;
</script>

然后document.getElementById('tfa_200').name将包含utm_source.


推荐阅读