Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post

    jquery validate file stops form from submitting

    Solved - Please Lock

    Hey guys i am using jquery validate library for my form validation, but the code I wrote for it mustn't be correct because with it my form wont submit. I commented out the include for my validation code and it works so i narrowed it down to that, but I am a beginner so I don't understand what is wrong with it or exactly how it works....
    The web page the form is on is http://biggtire.com/contact.html


    Here is the code for the validation:

    Code:
    jQuery.validator.setDefaults({
    	debug: true,
    	success: "valid"
    });;
      jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
        phone_number = phone_number.replace(/\s+/g, ""); 
    	return this.optional(element) || phone_number.length > 9 &&
    		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
    	}, "Please specify a valid phone number.");
    
      $(document).ready(function(){
        $("#appointment").validate({
      rules: {
        name: {
          required: true
        },
    	PhoneNumber: {
    		required:true,
    		phoneUS: true
    	},
    	date: {
    		required: true,
    		date: true
    	},
    	email: {
    		required: false	
    	}
      },
      messages: {
    	name: "Please specify your name.",
    	PhoneNumber: {
    		required: "We need your phone number to contact you."
    	},
    	date: {
    		required: "We need the date you would like your appointment to be.",
    		date: "Please enter a valid date."
    	}
      }
    });
      });
    		$(document).ready(function() {
    			$('input[type="text"]').addClass("idleField");
           		$('input[type="text"]').focus(function() {
           			$(this).removeClass("idleField").addClass("focusField");
        		    if (this.value == this.defaultValue){ 
        		    	this.value = '';
    				}
    				if(this.value != this.defaultValue){
    	    			this.select();
    	    		}
        		});
        		$('input[type="text"]').blur(function() {
        			$(this).removeClass("focusField").addClass("idleField");
        		    if ($.trim(this.value) == ''){
    			    	this.value = (this.defaultValue ? this.defaultValue : '');
    				}
        		});
    		});
    Last edited by firetag; 07-17-2009 at 06:34 PM.

  • #2
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post
    Sorry for double post but i solved it so please lock it...

  • #3
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Would you please post your correction here so other people might benefit from it.
    Thank you.

  • #4
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post
    Sure it was actually quite simple.

    The line of code underlined below wasn't needed so I took it out. It could have been one of two things. The debugging built into jquery validation could have been conflicting with the validation built into the form mail script i used. Or the other theory which seems more realistic is that the debugger in jquery found something and returned false in turn not letting the form be submitted. So the fix was to just delete the line of code.

    Code:
    jQuery.validator.setDefaults({
    	debug: true,
    	success: "valid"
    });;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •