我有一个表单,我试图用POST提交。当我去捕捉POST变量时,没有发送任何内容。
<?php require_once("../includes/initialize.php"); ?>
<html><head>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.8.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('form').submit(function (e) {
var $this = $(this);
e.preventDefault(); // This prevents the form submission.
$("#messageSent").show("slow");
$this.closest('#contactForm').slideUp('slow', function () {
$this[0].submit(); // Actual submission.
});
});
$("#contactLink").click(function(){
if ($("#contactForm").is(":hidden")){
$("#contactForm").slideDown("slow");
}else{
$("#contactForm").slideUp("slow");
}
});
});
</script></head><body>
<?php
if(isset($_POST['signupSubmit'])){
echo "Post is set";
echo $_POST['name'], "<br />";
echo $_POST['email'];
}else{
echo "post is not set";
}
if(isset($_POST['signupSubmit'])){
$signup = new Signup();
$signup->name = $_POST['name'];
$signup->email = $_POST['email'];
if($signup->save()) {
$session->message("We will contact you with details.");
} else {
$session->message("Failed", $signup->errors);
}
}
echo output_message($message);
?>
<div id="contactFormContainer">
<div id="contactLink"></div>
<div id="contactForm">
<form action="test2.php" enctype="multipart/form-data" method="post">
<fieldset>
<label for="name">Name *</label>
<input id="name" type="text" name="name" />
<label for="email">Email address *</label>
<input id="email" type="text" name="email" />
<input id="sendMail" type="submit" name="signupSubmit" />
<span id="messageSent"></span>
</fieldset>
</form>
</div>
</div>
</body>
</html>
任何帮助将不胜感激!
答案 0 :(得分:2)
那是因为当您使用$this[0].submit();
提交表单时,它仍会运行提交处理程序,该处理程序无条件地阻止表单提交。设置一些标志,以便在动画后提交表单。
$('form').submit(function (e) {
var $this = $(this);
if (!$this.data('afteranimation')){
$("#messageSent").show("slow");
$this.closest('#contactForm').slideUp('slow', function () {
$this.data('afteranimation', true);
$this.submit(); // Actual submission.
});
e.preventDefault(); // This prevents the form submission.
}
});