admin管理员组文章数量:1404589
I have used the following code to successfully redirect a form to an URL after submission using contact form 7.
<add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '947' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page
location = '/';
} else if ( '1070' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
location = '/';
} else { // Sends submissions on all unaccounted for forms to the third thank you page
location = '/';
}
}, false );
</script>
<?php
}
Can this be modified to redirect once a certain field contains a certain value (for example [Post-Code] Contains KA7) and another field contains a value (for example [Bedrooms] == 1) ?
Thanks in advance
Andy
I have used the following code to successfully redirect a form to an URL after submission using contact form 7.
<add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '947' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page
location = 'https://www.example/thank-you-1/';
} else if ( '1070' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
location = 'https://www.example/thank-you-2/';
} else { // Sends submissions on all unaccounted for forms to the third thank you page
location = 'https://www.example/thank-you-3/';
}
}, false );
</script>
<?php
}
Can this be modified to redirect once a certain field contains a certain value (for example [Post-Code] Contains KA7) and another field contains a value (for example [Bedrooms] == 1) ?
Thanks in advance
Andy
Share Improve this question edited Mar 19, 2019 at 12:22 Andy Strachan asked Mar 19, 2019 at 11:46 Andy StrachanAndy Strachan 11 silver badge3 bronze badges1 Answer
Reset to default 1Yes, you should be able access the form fields and field values with event.detail.inputs
in addEventListener
on wpcf7mailsent
. You can then use the field values in the conditional statements and add the redirects you need. There's a simple code sample in the plugin doumentation, https://contactform7/dom-events/, for looping the fields.
EDIT Here's a code example,
document.addEventListener( 'wpcf7mailsent', function( event ) {
var inputs = event.detail.inputs,
inputCount = inputs.length,
firstCondition,
secondCondition;
for ( var i = 0; i < inputCount; i++ ) {
if ( 'first-condition-field' == inputs[i].name ) {
firstCondition = inputs[i].value
} else if ( 'second-condition-field' == inputs[i].name ) {
secondCondition = inputs[i].value
}
}
if ( 'foo' == firstCondition && 'bar' == secondCondition ) {
location = 'https://www.example/thank-you-1/';
} else if ( 'bar' == firstCondition && 'baz' == secondCondition ) {
location = 'https://www.example/thank-you-2/';
}
}, false );
本文标签: functionsContact Form 7 If Condition
版权声明:本文标题:functions - Contact Form 7 If Condition 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744839452a2627833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论