jQuery Form Validation

I've got a form that I use jquery to do some of the light lifting like serializing multiple inputs into one field.

I need to add validation to the form but haven't been able to get it working. Is there anything obvious in my code (below) that would keep it from working? It just submits without doing any validation.




 
$("#freeform").validate({
	rules: {
		full_name: "required",
		organization: "required",
		email_address: {
			required: true,
			email: true
		},
	messages: {
		full_name: "Please enter your full name",
		organization: "Please enter your Company Name",
		email_address: "Please enter a valid email address"
		},

	submitHandler: function(form) {
		//setup variables
		part_numbers = "";
		nsns = "";
		quantity_required = "";
		condition_required = "";
		
			$.map( $("[name^='parts[parts]'][name$='[part_numbers]']").serializeArray(), function(el,i) { part_numbers += ( ((i>0)?"|":"") + el.value) });
			$.map( $("[name^='parts[parts]'][name$='[nsns]']").serializeArray(), function(el,i) { nsns += ( ((i>0)?"|":"") + el.value) });
			$.map( $("[name^='parts[parts]'][name$='[quantity_required]']").serializeArray(), function(el,i) { quantity_required += ( ((i>0)?"|":"") + el.value) });
			$.map( $("[name^='parts[parts]'][name$='[condition_required]']").serializeArray(), function(el,i) { condition_required += ( ((i>0)?"|":"") + el.value) });
		
			$("#part_number").val( part_numbers );
			$("#nsns").val( nsns );
				  
			$("#quantity_required").val( quantity_required );
			$("#condition_required").val( condition_required );
			//alert( part_numbers );
		
			if ( $("input[name='file1']").val() == "" )
			{
			$("input[name='part_list_attached']").val("No");
		} else {
			$("input[name='part_list_attached']").val("Yes");
		}
		
		if ( $("input[name='file2']").val() == "" )
		{
			$("input[name='end_user_doc_attached']").val("No");
		} else {
			$("input[name='end_user_doc_attached']").val("Yes");
		}
		form.submit();
	}
});

Open in new window

LVL 1
befidledAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PredicateCommented:
Hello befidled,

What happens if you change your mapping statements to append the serialized array values to your string vars using the array[index] notation?

For example: instead of appending "el.value" to your string vars, do "el[index].value" instead.


$.map( $("[name^='parts[parts]'][name$='[part_numbers]']").serializeArray(), function(el,i) { part_numbers += ( ((i>0)?"|":"") + el[i].value) });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
befidledAuthor Commented:
The form is set up to allow a user to add rows of data for the portions that use the $.map statements and changing el.value to el[index].value breaks that functionality.

How do you think that might affect the validation?
0
Ray PaseurCommented:
Since we do not have the HTML here, I can't quite follow what you're trying to do with the JavaScript, but please remember that you must validate the data on the server side before you use it in any script that can modify the data model.  Form data is external input, and therefore by definition it is tainted.  Nice guys will appreciate your efforts to make a good UI experience with JavaScript.  Bad guys will not really care; they will bypass the JavaScript and post toxic data directly into your action script.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.