Skip to content

Instantly share code, notes, and snippets.

@Glinkfr
Created November 21, 2023 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glinkfr/e18c7bd979df76fdc0ce451fbb16531b to your computer and use it in GitHub Desktop.
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
/**
* 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