我有一个cf7,其中包含3个字段:名称,电子邮件和选择框,并且在下拉列表中,基于选择表单将重定向到不同的“谢谢”页面。问题是,如果表单显示一些错误消息,例如发送消息时出错,输入无效等,则表单不应重定向到“谢谢”页面。
我尝试了联系表7自定义DOM事件,如wpcf7mailfailed,wpcf7invalid。
function cf7_footer_script(){ ?>
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
if ( '7084' == event.detail.contactFormId ) {
var lpLocation = document.getElementById("careers").value;
if (lpLocation == "Hire better employees") {
location = 'url1';
} else if (lpLocation == "I want to match people to the best careers") {
location = 'url2';
}
else if(lpLocation=="I want to learn more about both"){
location = 'url3';
}
}
}, false );
</script>
<?php }
add_action('wp_footer', 'cf7_footer_script');
我想防止错误重定向。
答案 0 :(得分:0)
You can try with this "document.addEventListener( 'wpcf7mailsent', function( event ) "
function cf7_footer_script(){ ?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '7084' == event.detail.contactFormId ) {
var lpLocation = document.getElementById("careers").value;
if (lpLocation == "Hire better employees") {
location = 'url1';
} else if (lpLocation == "I want to match people to the best careers") {
location = 'url2';
}
else if(lpLocation=="I want to learn more about both"){
location = 'url3';
}
}
}, false );
</script>
<?php }
add_action('wp_footer', 'cf7_footer_script');
答案 1 :(得分:0)
使用 wpcf7mailsent 代替 wpcf7submit 事件。
答案 2 :(得分:0)
您只需要更改联系表7自定义DOM事件,请使用wpcf7mailsent而不是wpcf7submit。
wpcf7mailsent-在Ajax表单提交成功完成并且已发送邮件时触发。
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '7084' == event.detail.contactFormId ) {
var lpLocation = document.getElementById("careers").value;
if (lpLocation == "Hire better employees") {
location = 'url1';
} else if (lpLocation == "I want to match people to the best careers") {
location = 'url2';
}
else if(lpLocation=="I want to learn more about both"){
location = 'url3';
}
}
}, false );
</script>
<?php }
add_action('wp_footer', 'cf7_footer_script');