javascript - 如何将变量字段名称放入 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 失败。
// 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.
解决方案
你有没有试过这个:
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
.
推荐阅读
- javascript - 在javascript中对混合服装尺寸的数组进行排序
- sql - 如果在 SQL 查询中满足特定条件,有没有办法只返回某些值?
- javascript - 使用提供的 id 删除数组中的对象
- c# - WeakReference 在 .Net Framework 和 .Net Core 之间的行为不同
- windows - Git在回购中令人讨厌地坚持
- node.js - 使用 Express 在 Nodejs 中发送和接收文件
- php - 我在使用管理员时在 codeigniter 管理员和用户中有 2 个角色,然后 ajax 给出响应,但在其他角色中它成功但控制器没有响应
- mongodb - Mongoose,按日期过滤子文档数组
- java - Selenium webdriver java - 自动化 Dojo 下拉菜单 - 没有这样的元素异常
- python - ModuleNotFoundError:当我通过 virtualenv 创建新环境时,没有名为“virtualenv.seed.embed.via_app_data”的模块