-
-
Save ildarkhasanshin/2762423951cec81643ff90263a526080 to your computer and use it in GitHub Desktop.
Displays a message about the successful submission of the form in a modal window for the Contact Form 7 plugin
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
<?php | |
/** | |
* Plugin Name: CF7 Modal Right Answer | |
* Plugin URI: https://gist.github.com/campusboy87/a056c288c99feee70058ed24cee805ad | |
* Author: Campusboy (wp-plus) | |
* Author URI: https://www.youtube.com/wp-plus | |
*/ | |
add_action( 'wp_enqueue_scripts', 'wpcf7_modal_right_answer_js' ); | |
add_action( 'wp_footer', 'wpcf7_modal_right_answer_js_inline', 999 ); | |
/** | |
* Поключает библиотеку sweetalert.js для создания красивых модальных окон. | |
* | |
* @link https://sweetalert.js.org/ | |
* | |
* @return void | |
*/ | |
function wpcf7_modal_right_answer_js() { | |
wp_enqueue_script( 'sweetalert', 'https://unpkg.com/sweetalert/dist/sweetalert.min.js' ); | |
} | |
/** | |
* Выводит на экран модальное окно при успешной отправки формы. | |
* | |
* @return void | |
*/ | |
function wpcf7_modal_right_answer_js_inline() { | |
?> | |
<script> | |
// Срабатывает при успешной отправке формы. | |
document.addEventListener('wpcf7mailsent', function (response) { | |
// Запускает модальное окно. | |
swal({ | |
title: "Спасибо!", | |
text: response.detail.apiResponse.message, | |
icon: "success", | |
button: "Закрыть" | |
}); | |
}, false); | |
</script> | |
<style> | |
.wpcf7-mail-sent-ok { | |
display: none !important; | |
} | |
</style> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment