联系表单7:提交时多行javascript

联系表单7:提交时多行javascript,javascript,wordpress,forms,contact-form-7,Javascript,Wordpress,Forms,Contact Form 7,我需要使用联系人7有一个嵌入式表单,提交信息到我的病毒循环帐户 提交表单后,它需要运行以下代码,即发送时的\u确定: VL.options.form_fields.form_firstName = $("#firstname").val(); //capture the first name VL.options.form_fields.form_email = $("#email").val(); //capture the email VL.options.form_fields.form_

我需要使用联系人7有一个嵌入式表单,提交信息到我的病毒循环帐户

提交表单后,它需要运行以下代码,即发送时的
\u确定:

VL.options.form_fields.form_firstName = $("#firstname").val(); //capture the first name
VL.options.form_fields.form_email = $("#email").val(); //capture the email
VL.options.form_fields.form_lastName = $("#lastname").val(); //capture the last name (if applicable in your form)
//submit the participant to Viral Loops
VL.createLead(function() {
//any logic to run after the participation
});
我不知道在哪里或如何添加它,因为在高级设置中只能有一行代码使用on sent ok。


提前谢谢!!:)

如评论中所述,缩小:

on_sent_ok: "VL.options.form_fields.form_firstName = $('#firstname').val();VL.options.form_fields.form_email = $('#email').val();VL.options.form_fields.form_lastName = $('#lastname').val();VL.createLead(function() {});"

或者,您可以在
js/script.js
中的(子)主题目录中创建一个JavaScript文件,然后将其添加到(子)主题目录中的
functions.php

/**
 * Enqueue a script with jQuery as a dependency.
 */
function so_40916565_enqueue() {
    wp_enqueue_script( 'so-40916565', get_stylesheet_directory_uri() . '/js/script.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'so_40916565_enqueue' );
在新创建的javascript文件中:

function js_40916565() {
  VL.options.form_fields.form_firstName = $("#firstname").val(); //capture the first name
  VL.options.form_fields.form_email = $("#email").val(); //capture the email
  VL.options.form_fields.form_lastName = $("#lastname").val(); //capture the last name (if applicable in your form)
  //submit the participant to Viral Loops
  VL.createLead(function() {
    //any logic to run after the participation
  });
}
在您的联系方式表7中:

on_sent_ok: "js_40916565();"

我还没有实际测试过它,所以如果它不能立即运行,请留下评论。

如评论中所述,缩小它:

on_sent_ok: "VL.options.form_fields.form_firstName = $('#firstname').val();VL.options.form_fields.form_email = $('#email').val();VL.options.form_fields.form_lastName = $('#lastname').val();VL.createLead(function() {});"

或者,您可以在
js/script.js
中的(子)主题目录中创建一个JavaScript文件,然后将其添加到(子)主题目录中的
functions.php

/**
 * Enqueue a script with jQuery as a dependency.
 */
function so_40916565_enqueue() {
    wp_enqueue_script( 'so-40916565', get_stylesheet_directory_uri() . '/js/script.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'so_40916565_enqueue' );
在新创建的javascript文件中:

function js_40916565() {
  VL.options.form_fields.form_firstName = $("#firstname").val(); //capture the first name
  VL.options.form_fields.form_email = $("#email").val(); //capture the email
  VL.options.form_fields.form_lastName = $("#lastname").val(); //capture the last name (if applicable in your form)
  //submit the participant to Viral Loops
  VL.createLead(function() {
    //any logic to run after the participation
  });
}
在您的联系方式表7中:

on_sent_ok: "js_40916565();"

我还没有真正测试过它,所以如果它不能立即运行,请留下评论。

它不是最可读的,但是为什么不把所有的js放在一行呢?分号会区分任何一条语句的结尾,或者你可以把它作为一个函数放在一个外部JS文件中,你已经把它编入队列()并从中调用函数。虽然分号不是最可读的,但是为什么不把所有的JS放在一行呢?分号将负责区分任何一条语句的结尾。也可以将其作为函数放入已排队()的外部JS文件中,并在发出时调用该函数,但该函数不起作用:(我的js应该一开始就有这个吗?
没有,对不起。也许我的帖子不够清楚。
函数js_40916565
块中的代码应该在你的
js/script.js
文件中,没有其他内容(除非该文件已经存在)。将jQuery作为依赖项的
脚本排队
块应该在
functions.php
文件中,并且on_sent_ok显然应该在WordPress admin中的Form 7中。是的,我已经这样做了,但我正在使用Gem主题,它在主题选项中有自定义js-我在那里添加了
函数
位nqueue
位在my functions.php文件中,文件中已经有
是的,该链接确实有帮助。因为您已经在主题选项中添加了javascript函数,所以不需要在
functions.php
文件中添加代码,事实上,您应该从functions.php中删除代码,因为网站尝试加载文件
js/script.js
不存在。最后,您还没有更新联系人表单7中的代码。将on_sent_ok更改为
on_sent_ok:“js_40916565();”
。您就快到了!哦,您必须将id添加到CF7字段中。示例
[电子邮件*电子邮件id:电子邮件占位符“电子邮件地址*”]
还是不走运。病毒循环的家伙给了我一些js代码
函数js_40916565(){VL.options.form_fields.form_firstName=jQuery(“#firstName”).val();VL.options.form_fields.form_email=jQuery(#email”).val();VL.options.form_lastName=jQuery(“#lastName”).val();VL.extraData[“rNk0t3ZC”=jQuery(“#国家”).val();VL.createLead(函数(){//参与后运行的任何逻辑});}
annd我从函数文件中取出了内容。它不起作用:(我的js应该一开始就有这个吗?
没有,对不起。也许我的帖子不够清楚。
函数js_40916565
块中的代码应该在你的
js/script.js
文件中,没有其他内容(除非该文件已经存在)。将jQuery作为依赖项的
脚本排队
块应该在
functions.php
文件中,并且on_sent_ok显然应该在WordPress admin中的Form 7中。是的,我已经这样做了,但我正在使用Gem主题,它在主题选项中有自定义js-我在那里添加了
函数
位nqueue
位在my functions.php文件中,文件中已经有
是的,该链接确实有帮助。因为您已经在主题选项中添加了javascript函数,所以不需要在
functions.php
文件中添加代码,事实上,您应该从functions.php中删除代码,因为网站尝试加载文件
js/script.js
不存在。最后,您还没有更新联系人表单7中的代码。将on_sent_ok更改为
on_sent_ok:“js_40916565();”
。您就快到了!哦,您必须将id添加到CF7字段中。示例
[电子邮件*电子邮件id:电子邮件占位符“电子邮件地址*”]
还是不走运。病毒循环的家伙给了我一些js代码
函数js_40916565(){VL.options.form_fields.form_firstName=jQuery(“#firstName”).val();VL.options.form_fields.form_email=jQuery(#email”).val();VL.options.form_lastName=jQuery(“#lastName”).val();VL.extraData[“rNk0t3ZC”=jQuery(“#国家”).val();VL.createLead(函数(){//参与后运行的任何逻辑});}
annd我从函数文件中取出了内容。