javascript - 联系表 7 : multiple lines of javascript on submit

标签 javascript wordpress forms contact-form-7

我需要使用 Contact 7 拥有一个嵌入式表单,将信息提交到我的 Viral Loops 帐户。

提交表单后需要运行以下代码,即on_sent_ok:

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 send 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 文件,然后将其添加到 (子)主题目录:

/**
 * 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();"

我还没有实际测试过它,所以如果它不能立即工作,请发表评论。

关于javascript - 联系表 7 : multiple lines of javascript on submit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40916565/

相关文章:

javascript - 打开图形在单页应用程序 AngularJs 中无法正常工作

wordpress - 设置评论元 REST API WordPress

jquery - 一旦它到达容器 div,将导航栏背景更改为黑色

javascript - PHP 和 JavaScript 结合在一起

javascript - 单击转到模态部分

javascript - 如何捕获UWP Web应用程序的屏幕

javascript - 无法使用获取 POST 方法对未安装的组件执行 React 状态更新

WordPress 插件开发

python - Django:将表单数据转换为 'clean url'

javascript - 每次完成一个部分时提交表格的最佳方式