Validate Plugin - Form submitted to server side with a blank value but passing client side rules
Hi All,
I'm using the jQuery validate plugin (v 1.9) for a contact form on a site. The contact form is really simple, 3 fields, name (input), email(input), enquiry(textarea).
The form has on a few occasions been allowed to submit (passing the client side rules) but not providing a value to the server side for the email field. I'm confident there is no issue passing the data (as it works 99% of the time) and also that these aren't hacky/bot/js disabled attempts, as the rest of the content is legitimate, just the email appears empty.
I just wanted a sanity check to make sure I was using the plugin correctly, and also any ideas as to how someone would have managed to submit the form without providing valid content for the email field.
Code samples:
- <form id="contact" action="#" name="contact" hidden="true" novalidate="novalidate" style="display: block; ">
- <p><strong>General Enquiry</strong></p>
- <dl>
- <dt><label for="name">Name</label></dt>
- <dd>
- <input id="name" class="required" type="text" name="name"></dd>
- </dl>
- <dl>
- <dt><label for="email">Email</label></dt>
- <dd>
- <input id="email" class="required" type="text" name="email"></dd>
- </dl>
- <dl>
- <dt><label for="enquiry">How can we help?</label></dt>
- <dd><textarea id="enquiry" class="required" name="enquiry" rows="8" cols="50"></textarea></dd>
- </dl>
- <input id="submit" class="sendButton" type="submit" value="Send">
- </form>
My JS for the validation:
- //setup the client side form validation
- $("#contact").validate({
- rules: {
- name: { required: true, minlength: 3 },
- email: { required: true, email: true },
- enquiry: { required: true, minlength: 5 }
- },
- messages: {
- name: "Please enter your name",
- email: "Please enter a valid email address",
- enquiry: "Please enter you enquiry detail"
- }
- });
And my form submission code:
- //bind the submit event on the form
- $('#contact').submit(function(e) {
- //if the form is valid
- if($("#contact").valid()) {
-
- //get the data from the form, TODO: use serialise here
- var name = $('input[name=name]').val();
- var email = $('input[name=email]').val();
- var enquiry = $('textarea[name=enquiry]').val();
- var data = '&type=' + type + '&name='+ name + '&email=' + email + '&enquiry=' + enquiry;
-
- //send the Ajax request
- $.ajax({
- type: "POST",
- url: "myUrl.php",
- data: data,
- success: function() {
- $('#contact').html("<div id='message'></div>");
- $('#message').html("<h3>Contact Form Submitted</h3>")
- .append("<p>We will be in touch soon, thank you for your time.</p>")
- .hide()
- .fadeIn(1500)
- }
- }); //end ajax request
- e.preventDefault();
- return false;
- } //end if valid block
- }); //end submit handler
Does anything here look out of place?