[英]Redirect to URL, specified by form value, on submit of Contact Form 7
我已经使用WordPress的Contact Form 7插件创建了一个表单。
我的表格如下所示:
<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 URL)。
如果某人选择“支票”付款方式并单击以提交表单,它将把他重定向到“谢谢”页面。
使用Contact Form 7插件时如何实现?
将以下代码添加到“其他设置”,但根据您的要求更改ID和值:
on_sent_ok: " if (document.getElementById('car').value=='yes') {location.replace('http://www.redirectedpage1.com')} else { location.replace('http://www.redirectedpage2.com/') } "
您可以添加一个钩子,该钩子在表单提交后但邮件发送之前触发。 关于WP:SE的问题对此有几个答案。
当您迷上了该流程时,您将可以访问所提交表单的内容,从而可以访问所选的Payment方法。
您可以检查选定的值并根据该值进行重定向。 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>
您可以尝试上面的代码吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.