【问题标题】:Use 'on sent ok' action hook for two actions - Contact Form 7/WordPress对两个操作使用“发送成功”操作挂钩 - 联系表 7/WordPress
【发布时间】:2014-02-19 13:49:15
【问题描述】:

我需要使用on sent ok 操作挂钩来执行两项操作:1) 跟踪电子邮件地址和 2) 将用户发送到感谢页面。我尝试将其添加到 Contact Form 7 面板上的“其他设置”部分,但我不确定它是否正常工作。至少我在使用两种不同的形式时得到了不同的结果。

on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]);"

on_sent_ok: "location.replace('http://xxxxx.com/thank-you');"

两次使用动作钩子是否可以,或者我可以以某种方式组合它吗?非常感谢您的帮助!

【问题讨论】:

    标签: javascript wordpress contact-form-7


    【解决方案1】:

    你不能直接在fnTransaction()-function 中调用location.replace('http://xxxxx.com/thank-you'); 吗?

    编辑:

    编写一个结合两者的新函数:

    on_sent_ok: "mySentOkFunction('Contacted', 'userid=' + [your-email]);"
    
    function mySentOkFunction(param1, param2){
        fnTransaction(param1, param2);
        location.replace('http://xxxxx.com/thank-you');
    }
    

    【讨论】:

    • fnTransaction() 由第三方 PPC 公司提供,所以很遗憾我无法真正编辑此函数。
    【解决方案2】:

    我不知道联系表 7,但您是否尝试过:

    on_sent_ok: "function(){ fnTransaction('Contacted', 'userid=' + [your-email]);location.replace('http://xxxxx.com/thank-you');}"
    

    【讨论】:

      【解决方案3】:

      你可以使用:

      on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]); location.replace('http://xxxxx.com/thank-you');"
      

      这里的 location.replace 不起作用,所以我正在使用:

      location = 'http://xxxxx.com/thank-you';
      

      这将是最终代码:

      on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]); location = 'http://xxxxx.com/thank-you';"
      

      【讨论】:

        【解决方案4】:

        一个干净的方法是在自定义插件中使用钩子wpcf7_contact_form_properties,这里是插件:

        /*
        Plugin Name: Multiple WPCF7's on_sent_ok
        Plugin URI: http://kadimi.com/wpcf7-javascript-programmatically
        Description: Use WPCF7's on_sent_ok many times.
        Author: Nabil Kadimi
        Version: 1.0
        Author URI: http://kadimi.com/
        */
        
        function se_21402617_wpcf7_properties( $properties, $contact_form_obj, $unused ){
            $properties[ 'additional_settings' ] .= 
                "\n"
                . 'on_sent_ok: "console.log(1);"' . "\n"
                . 'on_sent_ok: "console.log(2);"' . "\n"
                . 'on_sent_ok: "console.log(3);"' . "\n"
            ;
            return $properties;
        }
        add_filter( 'wpcf7_contact_form_properties', 'se_21402617_wpcf7_properties' , 10, 2 );
        

        正如你在插件代码中看到的,我使用了on_sent_ok 3次。

        您可以通过检查$contact_form_object 来筛选受影响的表单。

        来源:

        代码源自my blog post here

        【讨论】:

          猜你喜欢
          • 2017-10-02
          • 1970-01-01
          • 1970-01-01
          • 2015-07-22
          • 1970-01-01
          • 1970-01-01
          • 2011-10-10
          • 2015-08-02
          • 2015-02-19
          相关资源
          最近更新 更多