I am working with theme my login plugin in wordpress. I have created popup after theme my login register. I have written jquery to display popup when register form is submit.The code is like :
$('#registerform').submit(function(){
var mob = $("#cimy_uef_1").val();
var email = $("#user_email").val();
var pass1 = $("#pass1").val();
var pass2 = $("#pass2").val();
var len = $(".tml-register").find(".error").length;
if(email != '' && pass1 != '' && pass2 != '' && pass1 == pass2)
{
//alert("nisarg");
$.ajax
({
type: "POST",
url: "<?php echo plugins_url()."/invoice-system/send_sms.php"; ?>",
data: {mob:mob,email:email},
}).done(function(html){
$('.cd-popup').addClass('is-visible');
//close popup
$('.cd-popup').on('click', function(event){
if( $(event.target).is('.cd-popup-close') || $(event.target).is('.cd-popup') ) {
event.preventDefault();
$(this).removeClass('is-visible');
}
});
//close popup when clicking the esc keyboard button
setTimeout(function(){
$(document).keyup(function(event){
if(event.which=='27'){
$('.cd-popup').removeClass('is-visible');
}
});},10000);
});
}
Here the form is also submitted. When I submit form then page is reload so my popup is display for few seconds. Here I want to display popup after registration till I close popup. So what should I have to do?
First you need to stop form from submitting, you can do that using:
e.preventDefault();
Then you need to resubmit the form on popup close. You can do that using:
$( "#registerform" ).submit();
Your complete code will look like this:
$('#registerform').submit(function(e){ e.preventDefault(); var mob = $("#cimy_uef_1").val(); var email = $("#user_email").val(); var pass1 = $("#pass1").val(); var pass2 = $("#pass2").val(); var len = $(".tml-register").find(".error").length; if(email != '' && pass1 != '' && pass2 != '' && pass1 == pass2) { //alert("nisarg"); $.ajax ({ type: "POST", url: "<?php echo plugins_url()."/invoice-system/send_sms.php"; ?>", data: {mob:mob,email:email}, }).done(function(html){ $('.cd-popup').addClass('is-visible'); //close popup $('.cd-popup').on('click', function(event){ $( "#registerform" ).submit(); if( $(event.target).is('.cd-popup-close') || $(event.target).is('.cd-popup') ) { event.preventDefault(); $(this).removeClass('is-visible'); } }); //close popup when clicking the esc keyboard button setTimeout(function(){ $(document).keyup(function(event){ if(event.which=='27'){ $('.cd-popup').removeClass('is-visible'); } });},10000); }); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.