Created
November 21, 2023 13:11
-
-
Save Glinkfr/e18c7bd979df76fdc0ce451fbb16531b to your computer and use it in GitHub Desktop.
Snippet CF7 pour redirection en fonction de la réponse à un champ select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Contact form7 fonction de redirection | |
* A ajouter à votre fichier function.php de votre thème enfant | |
*/ | |
function cf7_redirectionl() { | |
?> | |
<script type="text/javascript" id="cf7-redirection"> | |
document.addEventListener( 'wpcf7mailsent', function( event ) { | |
// changer l'ID par votre ID de formulaire de contact | |
// ID visible dans le lien vers votre formulaire dans l'adrministration | |
// exemple : https://urlvotresite.fr/wp-admin/admin.php?page=wpcf7&post=567&action=edit | |
if(event.detail.contactFormId == '567') { | |
inputs = event.detail.inputs; | |
inputs.forEach( function(el) { | |
if ( el.name == 'your_redirect_page' ) { | |
if ( el.value == 'Oui' ) { | |
location.href = 'https://www.lesite.fr/lapage1'; | |
} else if ( el.value == 'Non' ) { | |
location.href = 'https://www.lesite.fr/lapage2'; | |
} | |
} | |
}); | |
} | |
}, false ); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'cf7_redicrection', PHP_INT_MAX ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment