Last active
March 28, 2024 11:20
-
-
Save campusboy87/a056c288c99feee70058ed24cee805ad 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 Invalid 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_invalid_js' ); | |
add_action( 'wp_footer', 'wpcf7_modal_invalid_js_inline', 999 ); | |
/** | |
* Поключает библиотеку sweetalert.js для создания красивых модальных окон. | |
* | |
* @link https://sweetalert.js.org/ | |
* | |
* @return void | |
*/ | |
function wpcf7_modal_invalid_js() { | |
wp_enqueue_script( 'sweetalert', 'https://unpkg.com/sweetalert/dist/sweetalert.min.js' ); | |
} | |
/** | |
* Выводит на экран модальное окно при ошибках валидации формы. | |
* | |
* @return void | |
*/ | |
function wpcf7_modal_invalid_js_inline() { | |
?> | |
<script> | |
// Срабатывает при ошибках валидации формы. | |
document.addEventListener('wpcf7invalid', function (response) { | |
// Запускает модальное окно. | |
swal({ | |
title: "Ошибка!", | |
text: response.detail.apiResponse.message, | |
icon: "error", | |
button: "Закрыть" | |
}); | |
}, false); | |
</script> | |
<style> | |
.wpcf7-validation-errors { | |
display: none !important; | |
} | |
</style> | |
<?php | |
} |
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_mailsent_js' ); | |
add_action( 'wp_footer', 'wpcf7_modal_mailsent_js_inline', 999 ); | |
/** | |
* Поключает библиотеку sweetalert.js для создания красивых модальных окон. | |
* | |
* @link https://sweetalert.js.org/ | |
* | |
* @return void | |
*/ | |
function wpcf7_modal_mailsent_js() { | |
wp_enqueue_script( 'sweetalert', 'https://unpkg.com/sweetalert/dist/sweetalert.min.js' ); | |
} | |
/** | |
* Выводит на экран модальное окно при успешной отправки формы. | |
* | |
* @return void | |
*/ | |
function wpcf7_modal_mailsent_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 | |
} |
Author
campusboy87
commented
Jul 4, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment