contact form 7提交成功后如何打开弹窗
How to open a popup after the contact form 7 succesfully submitted
我正在使用 Wordpress 和 Contact form 7。
我需要使用 magnificPopup js 显示一个弹出窗口,该弹出窗口将在成功提交联系表单后出现。
为 wpcf7_mail_sent 添加了一个挂钩,但我如何调用弹出窗口以显示使用 javascript。
示例:
在functions.php
add_action( 'wpcf7_mail_sent', 'after_send_mail_from_contact_form' );
function after_send_mail_from_contact_form($contact_form){
// what to do here
}
在 Custom.js 文件中
$('.pay_for_course').magnificPopup({
disableOn: 700,
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: false
});
试试这个
创建一个 bootstrap 模态弹出窗口,然后在 function.php
中添加此功能
<?php add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '34' == event.detail.contactFormId ) { // Change 123 to the ID of the form
jQuery('#myModal2').modal('show'); //this is the bootstrap modal popup id
}
}, false );
</script>
<?php } ?>
或
add_action('wpcf7_mail_sent', function ($cf7) {
// Run code after the email has been sent
$wpcf = WPCF7_ContactForm::get_current();
$wpccfid=$wpcf->id;
// if you wanna check the ID of the Form $wpcf->id
if ( '34' == $wpccfid ) { // Change 123 to the ID of the form
echo '
<div class="modal fade in formids" id="myModal2" role="dialog" style="display:block;" tabindex="-1">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content no_pad text-center">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="modal-header heading">
<h3 class="modal-title">Message Sent!</b></h3>
</div>
<div class="modal-body">
<div class="thanku_outer define_float text-center">
<h3>Thank you for getting in touch!</h3>
</div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
';
}
});
$('.wpcf7-mail-sent-ok').change(function(){
$('#form_success').fadeIn(400).addClass('modal-show').find('.modal-content-block-title').text($(this).text() );
});
按照以下步骤在格式良好的对话框中完全自定义联系人 form7 消息:
第 1 步:使用 cPanel 转到您的插件文件夹,打开 contact-form-7 文件夹。
步骤 2:在 contact-form-7 中探索包含文件夹并打开 contact-form.php 文件。
步骤 3:在提到的文件中搜索 form_response_output() 函数并将其替换为波纹管编辑函数。
public function form_response_output() {
$status = 'init';
$class = 'wpcf7-response-output';
$role = '';
$id='cookie-notice-popup';
$content = '';
if ( $this->is_posted() ) {
$role = 'alert';
$submission = WPCF7_Submission::get_instance();
$status = $submission->get_status();
$content = $submission->get_response();
switch ( $status ) {
case 'validation_failed':
$class .= ' wpcf7-validation-errors alert alert-danger';
break;
case 'acceptance_missing':
$class .= ' wpcf7-acceptance-missing alert alert-warning';
break;
case 'spam':
$class .= ' wpcf7-spam-blocked alert alert-dark';
break;
case 'aborted':
$class .= ' wpcf7-aborted alert alert-info';
break;
case 'mail_sent':
$class .= ' wpcf7-mail-sent-ok alert alert-success';
break;
case 'mail_failed':
$class .= ' wpcf7-mail-sent-ng alert alert-primary';
break;
default:
$class .= sprintf( ' wpcf7-custom-%s',
preg_replace( '/[^0-9a-z]+/i', '-', $status )
);
}
} else {
$class .= ' wpcf7-display-none alert alert-info';
}
$atts = array(
'class' => trim( $class ),
'role' => trim( $role ),
'id' => trim( $id ),
);
$atts = wpcf7_format_atts( $atts );
$output = sprintf( '<div %1$s>%2$s <span> X </span></div>',
$atts, esc_html( $content ) );
$output = apply_filters( 'wpcf7_form_response_output',
$output, $class, $content, $this, $status );
$this->responses_count += 1;
return $output;
}
第 4 步:将波纹管 CSS 添加到样式表文件中。
#notice-popup
{
border-radius:0px!important;
color: #fff !important;
background: #673ab7;
left:20% !important;
right:20% !important;
}
#cookie-notice-popup
{
bottom:5em !important;
position:fixed;
height:auto;
z-index:100000;
font-size:13px;
line-height:40px;
text-align:center;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
第 5 步:如果您想在点击时关闭弹出消息对话框,请将以下 JS 添加到您的 javascript 文件中:
$(document).ready(function(){$(".wpcf7-response-output").on("click",function(){$(this).hide("slow");})})
第 6 步:完成。
注意:请清除您的浏览器历史记录以及缓存、cookie 以获取结果。
我正在使用 Wordpress 和 Contact form 7。 我需要使用 magnificPopup js 显示一个弹出窗口,该弹出窗口将在成功提交联系表单后出现。 为 wpcf7_mail_sent 添加了一个挂钩,但我如何调用弹出窗口以显示使用 javascript。
示例:
在functions.php
add_action( 'wpcf7_mail_sent', 'after_send_mail_from_contact_form' );
function after_send_mail_from_contact_form($contact_form){
// what to do here
}
在 Custom.js 文件中
$('.pay_for_course').magnificPopup({
disableOn: 700,
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: false
});
试试这个
创建一个 bootstrap 模态弹出窗口,然后在 function.php
中添加此功能 <?php add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '34' == event.detail.contactFormId ) { // Change 123 to the ID of the form
jQuery('#myModal2').modal('show'); //this is the bootstrap modal popup id
}
}, false );
</script>
<?php } ?>
或
add_action('wpcf7_mail_sent', function ($cf7) {
// Run code after the email has been sent
$wpcf = WPCF7_ContactForm::get_current();
$wpccfid=$wpcf->id;
// if you wanna check the ID of the Form $wpcf->id
if ( '34' == $wpccfid ) { // Change 123 to the ID of the form
echo '
<div class="modal fade in formids" id="myModal2" role="dialog" style="display:block;" tabindex="-1">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content no_pad text-center">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="modal-header heading">
<h3 class="modal-title">Message Sent!</b></h3>
</div>
<div class="modal-body">
<div class="thanku_outer define_float text-center">
<h3>Thank you for getting in touch!</h3>
</div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
';
}
});
$('.wpcf7-mail-sent-ok').change(function(){ $('#form_success').fadeIn(400).addClass('modal-show').find('.modal-content-block-title').text($(this).text() ); });
按照以下步骤在格式良好的对话框中完全自定义联系人 form7 消息:
第 1 步:使用 cPanel 转到您的插件文件夹,打开 contact-form-7 文件夹。
步骤 2:在 contact-form-7 中探索包含文件夹并打开 contact-form.php 文件。
步骤 3:在提到的文件中搜索 form_response_output() 函数并将其替换为波纹管编辑函数。
public function form_response_output() {
$status = 'init';
$class = 'wpcf7-response-output';
$role = '';
$id='cookie-notice-popup';
$content = '';
if ( $this->is_posted() ) {
$role = 'alert';
$submission = WPCF7_Submission::get_instance();
$status = $submission->get_status();
$content = $submission->get_response();
switch ( $status ) {
case 'validation_failed':
$class .= ' wpcf7-validation-errors alert alert-danger';
break;
case 'acceptance_missing':
$class .= ' wpcf7-acceptance-missing alert alert-warning';
break;
case 'spam':
$class .= ' wpcf7-spam-blocked alert alert-dark';
break;
case 'aborted':
$class .= ' wpcf7-aborted alert alert-info';
break;
case 'mail_sent':
$class .= ' wpcf7-mail-sent-ok alert alert-success';
break;
case 'mail_failed':
$class .= ' wpcf7-mail-sent-ng alert alert-primary';
break;
default:
$class .= sprintf( ' wpcf7-custom-%s',
preg_replace( '/[^0-9a-z]+/i', '-', $status )
);
}
} else {
$class .= ' wpcf7-display-none alert alert-info';
}
$atts = array(
'class' => trim( $class ),
'role' => trim( $role ),
'id' => trim( $id ),
);
$atts = wpcf7_format_atts( $atts );
$output = sprintf( '<div %1$s>%2$s <span> X </span></div>',
$atts, esc_html( $content ) );
$output = apply_filters( 'wpcf7_form_response_output',
$output, $class, $content, $this, $status );
$this->responses_count += 1;
return $output;
}
第 4 步:将波纹管 CSS 添加到样式表文件中。
#notice-popup
{
border-radius:0px!important;
color: #fff !important;
background: #673ab7;
left:20% !important;
right:20% !important;
}
#cookie-notice-popup
{
bottom:5em !important;
position:fixed;
height:auto;
z-index:100000;
font-size:13px;
line-height:40px;
text-align:center;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
第 5 步:如果您想在点击时关闭弹出消息对话框,请将以下 JS 添加到您的 javascript 文件中:
$(document).ready(function(){$(".wpcf7-response-output").on("click",function(){$(this).hide("slow");})})
第 6 步:完成。
注意:请清除您的浏览器历史记录以及缓存、cookie 以获取结果。