Before I even write my problem I want to state that I have read numerous StackOverflow posts about this and I still am running into the same problem. Basically no matter how many ways I alter my code my form still submits without first validating to see if each area is filled. This is my code.
<form id="contact" method="post" action="E-mail-form.php" name="EmailFromMyWebsite">
<label for="name">Name</label> <br>
<input type="text" name="name" class="required" placeholder="Your Name" title=" (Your name is required)"> <br />
<label for="email">E-mail</label> <br>
<input type="email" name="email" class="required email" placeholder="[email protected]" title=" (Your email is required)"> <br />
<label for="message">Message/Comment</label> <br>
<textarea name="message" class="required" placeholder="Leave a brief message" title=" (Please leave me a brief message)"></textarea> <br />
<input type="button" name="submit" id="submit" value="Send Message" />
</form>
$(document).ready(function(){
$('#contact').validate({
rules: {
name: {required: true},
email: {required: true},
message: {required: true}
},
submitHandler: $(function(form){
$("#submit").on('click', function(){
var formData = $('#contact').serialize();
$.ajax({
type:"POST",
data:formData,
url:"E-mail-form.php",
done: function(data){
$('#contact').html('<p>Your message has been sent. I will reply to you shortly.</p>');
},
fail: function(data) {
$('#contact').html('<p>Sorry there was a problem your message was NOT sent.</p>');
}
});
return false;
});
})
});
});
Now I think the first thing someone is going to notice is that I have a function on submit, but I've tried removing that and my form simply won't submit even with the submitHandler. I think that's where the problem is occurring because when I look at other forums with this problem I don't understand what is causing the form to actually submit without that. Any help or explanation would be very helpful.