[英]wordpress contact form7, one form redirect to multiple thank you page based on is_page
I am looking for a solution on wordpress contact form7.我正在寻找有关 wordpress 联系表单 7 的解决方案。 either a plugin or in PHP code.
插件或 PHP 代码。 I am not looking for JavaScript solution.
我不是在寻找 JavaScript 解决方案。 as I have already found JavaScript solution.
因为我已经找到了 JavaScript 解决方案。 Again: I am looking for either plugin or PHP code .
再次:我正在寻找插件或PHP 代码。 I want to use one form (CF7) and it will redirect to multiple thank you pages based on from which page the form submitted.
我想使用一个表单 (CF7),它将根据表单提交的页面重定向到多个感谢页面。 Below example code.
下面的示例代码。
if is_page(1){
contact-form will go to thank-you-page-1
} else if is_page(2) {
contact-form will go to thank-you-page-2
}
You can do by this hook你可以通过这个钩子做
add_action('wpcf7_mail_sent', function ($cf7) {
// Run code after the email has been sent
$wpcf = WPCF7_ContactForm::get_current();
$wpccfid=$wpcf->id;
// if you wanna check the ID of the Form $wpcf->id
if ( '34' == $wpccfid ) { // Change 123 to the ID of the form
//you can use also if(is_page()){} condition
//redirect to url
wp_redirect('url of thank you page');
exit();
}
}
<?php if (is_page(array(1))) { ?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://page-link-1.com/';
}, false );
</script>
<?php } else if ( is_page(array(2))) { ?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://page-link-2.com/';
}, false );
</script>
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.