Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

jquery form validate

Hello Experts,

I am using jquery validate, code below.
what happens is when i click the submit button both error messages appears.
and when i click the submit button again then the error messages duplicate and duplicate...

How is it possible to echo one error message at a time meaning deal with each error at the time? And how is it possible to prevent it from infinite duplicates?

$('#form-contact').validate({
	rules: {
		name: {required:true},
		email: {required:true, email:true}				
	},		
	messages: {
	      name: "Please fill in your full name",
              email: "Please provide a valid email address"	
	},
	errorPlacement: function(error, element) {
	   error.appendTo("#error-placement");	
	}
	});
	});

Open in new window

0
Refael
Asked:
Refael
1 Solution
 
Michel PlungjanIT ExpertCommented:
0
 
Mark BradyCommented:
If you can't get it fixed then go back to using the good old javascript method and check for empty values then throw an alert or show the error to the user. Works every time.
0
 
sammySeltzerCommented:
If it was me, I would just use this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script type="text/javascript" src="jquery.validate.js"></script>
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
  <script>
  $(document).ready(function(){
    $("#commentForm").validate();
  });
  </script>

</head>
<body>


 <form class="cmxform" id="commentForm" method="get" action="">
 <fieldset>
   <legend>Email/Name validation</legend>
   <p>
     <label for="fullname">Name</label>
     <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
   </p>
   <p>
     <label for="cemail">E-Mail</label>
     <em>*</em><input id="cemail" name="email" size="25"  class="required email" />
   </p>
   <p>
     <input class="submit" type="submit" value="Submit"/>
   </p>
 </fieldset>
 </form>
</body>
</html>

Open in new window


Then grab the js code from here:

http://jzaefferer.github.com/jquery-validation/jquery.validate.js
0
 
RefaelAuthor Commented:
Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now