我使用Contact Form 7 plugin为WordPress创建了一个表单。
我的表单如下:
<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网站(只是PayPal网址)。
如果有人选择付款方式“检查”并点击提交表单,则会将其重定向到“谢谢”页面。
使用Contact Form 7插件时,如何实现这一目标?
答案 0 :(得分:1)
将以下代码添加到“其他设置”,但根据您的要求更改ID和值:
on_sent_ok: " if (document.getElementById('car').value=='yes') {location.replace('http://www.redirectedpage1.com')} else { location.replace('http://www.redirectedpage2.com/') } "
答案 1 :(得分:0)
您可以添加一个在提交表单时但在邮件发送之前触发的挂钩。 This question on WP:SE有几个答案。
当您亲自参与此过程时,您将可以访问所提交表单的内容,从而访问所选的付款方式。
您可以检查所选值并根据该值进行重定向。 wp_redirect
可以派上用场。
答案 2 :(得分:0)
根据单选按钮值重新定位联系表单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>
请您尝试上面的代码吗?