admin管理员组文章数量:1353265
I need to use the on sent ok
action hook for two actions 1) to track the email adress and 2) to send the user to a thank you page. I tried adding this into the 'Additional Settings' section on the Contact Form 7 panel but I am not sure if it works correctly. At least I got different results when using it with two different forms.
on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]);"
on_sent_ok: "location.replace('');"
Is it OK to use the action hook twice or can I bine this somehow? I'd appreciate your help!
I need to use the on sent ok
action hook for two actions 1) to track the email adress and 2) to send the user to a thank you page. I tried adding this into the 'Additional Settings' section on the Contact Form 7 panel but I am not sure if it works correctly. At least I got different results when using it with two different forms.
on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]);"
on_sent_ok: "location.replace('http://xxxxx./thank-you');"
Is it OK to use the action hook twice or can I bine this somehow? I'd appreciate your help!
Share Improve this question asked Jan 28, 2014 at 10:11 Charles IngallsCharles Ingalls 4,5615 gold badges27 silver badges33 bronze badges4 Answers
Reset to default 4couldn't you just call location.replace('http://xxxxx./thank-you');
inside the fnTransaction()
-function?
edit:
write a new function that bines both:
on_sent_ok: "mySentOkFunction('Contacted', 'userid=' + [your-email]);"
function mySentOkFunction(param1, param2){
fnTransaction(param1, param2);
location.replace('http://xxxxx./thank-you');
}
I don't know Contact Form 7 but have you tried this:
on_sent_ok: "function(){ fnTransaction('Contacted', 'userid=' + [your-email]);location.replace('http://xxxxx./thank-you');}"
You can use:
on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]); location.replace('http://xxxxx./thank-you');"
Here location.replace didn't work, so I'm using:
location = 'http://xxxxx./thank-you';
This would be the final code:
on_sent_ok: "fnTransaction('Contacted', 'userid=' + [your-email]); location = 'http://xxxxx./thank-you';"
A clean approach is to use the hook wpcf7_contact_form_properties
in a custom plugin, here is the plugin:
/*
Plugin Name: Multiple WPCF7's on_sent_ok
Plugin URI: http://kadimi./wpcf7-javascript-programmatically
Description: Use WPCF7's on_sent_ok many times.
Author: Nabil Kadimi
Version: 1.0
Author URI: http://kadimi./
*/
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 );
As you can see in the plugin code, I used on_sent_ok
3 times.
You can filter which form is affected by inspecting the $contact_form_object
.
Source:
Code is derived from my blog post here.
本文标签: javascriptUse 39on sent ok39 action hook for two actionsContact Form 7WordPressStack Overflow
版权声明:本文标题:javascript - Use 'on sent ok' action hook for two actions - Contact Form 7WordPress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743928569a2563417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论