我有一个带有3个字段的CF7:姓名,电子邮件和选择框以及在下拉列表中,基于选择,将重定向到不同的感谢页面。问题是,是否显示一些错误消息,例如发送消息,无效输入等错误等。该表单不应重定向到谢谢页面。
我尝试了联系表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');
我想防止重定向错误。
您只需要更改联系表格7自定义DOM事件,使用WPCF7Mailsent而不是WPCF7SUBMIT。
wpcf7mailsent - 当Ajax表单提交成功完成并发送了邮件时,请发送。 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' );
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');
使用 wpcf7mailsent 而不是 wpcf7submit event。