I am using WordPress and Contact form 7. I need to show a popup using magnificPopup js which will come after the successfully submission of the contact form. Have added an hook for the wpcf7_mail_sent, but how can I call popup to show using javascript.
Example :
In functions.php
JavaScript
x
5
1
add_action( 'wpcf7_mail_sent', 'after_send_mail_from_contact_form' );
2
function after_send_mail_from_contact_form($contact_form){
3
// what to do here
4
}
5
in Custom.js file
JavaScript
1
9
1
$('.pay_for_course').magnificPopup({
2
disableOn: 700,
3
type: 'iframe',
4
mainClass: 'mfp-fade',
5
removalDelay: 160,
6
preloader: false,
7
fixedContentPos: false
8
});
9
Advertisement
Answer
Try this
create a bootstrap modal popup then add this function in function.php
JavaScript
1
12
12
1
<?php add_action( 'wp_footer', 'mycustom_wp_footer' );
2
function mycustom_wp_footer() {
3
?>
4
<script type="text/javascript">
5
document.addEventListener( 'wpcf7mailsent', function( event ) {
6
if ( '34' == event.detail.contactFormId ) { // Change 123 to the ID of the form
7
jQuery('#myModal2').modal('show'); //this is the bootstrap modal popup id
8
}
9
}, false );
10
</script>
11
<?php } ?>
12
OR
JavaScript
1
32
32
1
add_action('wpcf7_mail_sent', function ($cf7) {
2
// Run code after the email has been sent
3
$wpcf = WPCF7_ContactForm::get_current();
4
$wpccfid=$wpcf->id;
5
// if you wanna check the ID of the Form $wpcf->id
6
if ( '34' == $wpccfid ) { // Change 123 to the ID of the form
7
echo '
8
<div class="modal fade in formids" id="myModal2" role="dialog" style="display:block;" tabindex="-1">
9
<div class="modal-dialog">
10
11
<!-- Modal content-->
12
<div class="modal-content no_pad text-center">
13
<button type="button" class="close" data-dismiss="modal">×</button>
14
<div class="modal-header heading">
15
<h3 class="modal-title">Message Sent!</b></h3>
16
</div>
17
<div class="modal-body">
18
19
<div class="thanku_outer define_float text-center">
20
<h3>Thank you for getting in touch!</h3>
21
</div>
22
</div>
23
<div class="modal-footer">
24
</div>
25
</div>
26
27
</div>
28
</div>
29
';
30
}
31
});
32