表格不会在div内提交

时间:2014-09-26 15:13:03

标签: html

我似乎无法弄清楚为什么这个表单不会提交并发布到我指示的页面。当我点击提交按钮(称为发送表单)时,它什么都没做。

<div class="form-wrapper clearfix">
<form action="mail-sent.php" method="post" enctype="multipart/form-data" class="form-contact             email-form" id="form1">
<div class="inputs-wrapper">
<input class="form-name validate-required" type="text" placeholder="Your Name" name="name">
<input class="form-email validate-required validate-email" type="text" name="email"   placeholder="Your Email Address">
<textarea class="form-message validate-required" name="message" placeholder="Your Message">        </textarea>
</div>
<input type="submit" class="send-form" value="Send Form">
<div class="form-success">
<span class="text-white">Message sent - Thanks for your enquiry</span>
</div>
<div class="form-error">
<span class="text-white">Please complete all fields correctly</span>
</div>
</form>
</div>

这是javascript位:

// Contact form
$('form.email-form').submit(function (e) {
// return false so form submits through jQuery rather than reloading page.
if(e.preventDefault) e.preventDefault(); else e.returnValue = false;

console.log('We have a submission...');
var thisForm        = $(this).closest('.email-form'),
error           = 0,
originalError   = thisForm.attr('original-error');

if (typeof originalError !== typeof undefined && originalError !== false) {
thisForm.find('.form-error').text(originalError); 
}


$(thisForm).find('.validate-required').each(function(){
if($(this).val() === ''){
$(this).addClass('field-error');
error = 1;
}
else{
$(this).removeClass('field-error');
}
});

$(thisForm).find('.validate-email').each(function(){
if(!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))){
$(this).addClass('field-error');
error = 1;
}
else{
$(this).removeClass('field-error');
}
});


if (error === 1){
$(this).closest('.email-form').find('.form-error').fadeIn(200);
}
else{
jQuery.ajax({
type: "POST",
url: "mail/mail.php",
data: thisForm.serialize(),
success: function (response) {
// Swiftmailer always sends back a number representing numner of emails sent.
// If this is numeric (not Swift Mailer error text) AND greater than 0 then show success     message.
if($.isNumeric(response)){
if(parseInt(response) > 0){
thisForm.find('.form-success').fadeIn(1000);
thisForm.find('.form-error').fadeOut(1000);
setTimeout(function(){ thisForm.find('.form-success').fadeOut(500); }, 5000);
}
}
// If error text was returned, put the text in the .form-error div and show it.
else{
// Keep the current error text in a data attribute on the form
thisForm.find('.form-error').attr('original-error', thisForm.find('.form-error').text());
// Show the error with the returned error text.
thisForm.find('.form-error').text(response).fadeIn(1000);
thisForm.find('.form-success').fadeOut(1000);
}
}
});
}
return false;
});


});

$(window).load(function(){

"use strict";

0 个答案:

没有答案