Solved

jquery form validate

Posted on 2012-04-03
4
330 Views
Last Modified: 2012-04-08
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
Comment
Question by:Refael
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37804676
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 37806081
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
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 37807762
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
 

Author Closing Comment

by:Refael
ID: 37821865
Thank you!
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question