php 在Contact Form 7插件的模式窗口中显示有关成功提交表单的消息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在Contact Form 7插件的模式窗口中显示有关成功提交表单的消息相关的知识,希望对你有一定的参考价值。
<?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
}
<?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
}
以上是关于php 在Contact Form 7插件的模式窗口中显示有关成功提交表单的消息的主要内容,如果未能解决你的问题,请参考以下文章