简体   繁体   English

我应该如何使用Contact Form 7(wp)正确捕获提交的表单值?

[英]How should I properly capture submitted form values with Contact Form 7 (wp)?

I've recently done a GTM set up to track checkboxes for a WordPress Contact Form with contact form 7. I've obviously read this article from from Simo but to be honest I didn't really understand it so here is what I've finally done : 我最近完成了一个GTM设置,以跟踪带有联系表单7的WordPress联系表单的复选框。我显然是从Simo阅读这篇文章的 ,但老实说我不是很理解,所以这就是我已经了解的内容终于完成了 :

A custom Javascript : 自定义Javascript:

function checkbox_selector() {var array = ["group-963","group-964","group-965"];
    if ( document.getElementById(array[0]).style.display == "block" ) { return "Checkbox#1" }
    else if ( document.getElementById(array[1]).style.display == "block" ) { return "Checkbox#2" }
    else if ( document.getElementById(array[2]).style.display == "block" ) { return "Checkbox#3" }
    else { return "unchecked" }
}

I used this custom Javascript to fill the event action tracking parameters in an event tag. 我使用此自定义Javascript填充了事件代码中的事件操作跟踪参数。 The tag itself was fired on a simple form submission trigger. 标签本身是在简单的表单提交触发器上触发的。

Reading my custom Javascript you will understand that I didn't found any other solution than playing with display style of some elements. 阅读我的自定义Javascript,您将了解到,除了使用某些元素的显示样式之外,我没有找到其他解决方案。

Is there any way I could have done this job better ? 有什么办法可以更好地完成这项工作?

Created an example for you to play around with: 创建了一个示例供您试用:

 $('input[type=checkbox]').on('click', function() { var $this = $(this); var checkVal = $(this).is(':checked'); var checkName = $(this).attr('name'); // do your push to GTM here alert(checkName + ', ' + checkVal); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" name="tony" value="tony" /> <input type="checkbox" name="pepper" value="pepper" /> 

The fiddle here: https://jsfiddle.net/mrpharderwijk/56ef50og/1/ 这里的小提琴: https : //jsfiddle.net/mrpharderwijk/56ef50og/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM