在提交联系表单7时重定向到URL,由表单值指定
我使用Contact Form 7 plugin为WordPress创建了一个表单。在提交联系表单7时重定向到URL,由表单值指定
我的形式如下:
<label> Your Name (required)
[text* your-name] </label>
<label> Your Email (required)
[email* email]</label>
<label> Payment Method
[radio payment default:1 "Paypal" "Check"] </label>
[submit "Send"]
如果有人填写表格,并选择付款方式“贝宝”,并点击“发送”按钮,我想他重定向到PayPal网站(只一个PayPal网址)。
如果有人选择付款方式“支票”并点击提交表单,它会将他重定向到“谢谢”页面。
如何在使用联系表单7插件时实现此目的?
您可以添加一个挂钩,该挂钩在表单被提交但邮件发送之前触发。 This question on WP:SE有几个答案。
当您自己迷上进程时,您将有权访问提交表单的内容,因此可以访问所选的付款方式。
您可以检查选定的值并根据该值进行重定向。 wp_redirect
可以派上用场。
联系表7基于单选按钮值的重定向。
<script>
jQuery(document).ready(function($){
$(".wpcf7").on('mailsent.wpcf7', function(){
var redirect_to = $(this).find('#paypal-method').val(); // Enter your radio button id
if(typeof(redirect_to)!=='undefined' && redirect_to!=''){
if(redirect_to == 'Paypal'){
window.location.href= "https://www.paypal.com/";
}elseif(redirect_to == 'Check'){
window.location.href= "https://www.example.com/";
}
}
});
});
</script>
请您尝试上面的代码吗?
感谢您的建议,但如果填写并选择单选按钮作为“检查”,我希望通过邮件获取数据。这是可能的上述代码? – abu
@abu你没有提到你的问题。 – purvik7373
我的意思是在第一种情况下,表单将重定向到PayPal(此时数据不是通过邮件发送的),第二种情况下,表单将数据发送到所需的电子邮件地址以及重定向到某个页面,如“谢谢”。 – abu
添加下列根据您的要求的代码附加设置,但变化ID和值:
on_sent_ok: " if (document.getElementById('car').value=='yes') {location.replace('http://www.redirectedpage1.com')} else { location.replace('http://www.redirectedpage2.com/') } "
Go to PayPal像 –