Solved

form validation

Posted on 2011-03-11
12
324 Views
Last Modified: 2012-06-27
i need a simple form validator
it must be able to be called with a click event

thanks
0
Comment
Question by:dgrafx
  • 6
  • 5
12 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 35109582
http://bassistance.de/jquery-plugins/jquery-plugin-validation/

can help with your script if required...
0
 
LVL 25

Author Comment

by:dgrafx
ID: 35109688
this script says not yet compatible with 1.5
i am on 1.4 but I know others where I work are on 1.5
so if and when they need to use it - it will break

what are your comments on this?
thanks
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35109748
I've been using it successfully with the latest version of 1.5, with no major flaws, what I would say is to test your pages rigorously, there is a compatable version here:https://github.com/jzaefferer/jquery-validation:

off page: Please note: The latest release isn’t, yet, compatible with jQuery 1.5.x. You can find a compatible version in the GitHub repository.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 25

Author Comment

by:dgrafx
ID: 35109779
sounds good - I'll try it
so do you have some on page code (example)?
0
 
LVL 3

Expert Comment

by:ccwill88
ID: 35109785
0
 
LVL 25

Author Comment

by:dgrafx
ID: 35110343
ccwill - i like it but that wont fly here

need something real simple

looking for some example code guys
where you click and all fields then validated would be ideal

thanks
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35110500
Here are some demo's:

http://jquery.bassistance.de/validate/demo/

with further examples at the bottom of this page

0
 
LVL 25

Author Comment

by:dgrafx
ID: 35110581
ok - to clarify a bit more ...
I did stumble onto that page and tried to use the demo found there ...
I failed - didn't work.
I don't see what it is really doing ???
is it triggered by form submit?
I need it to be triggered by a click of a link that is not directly calling a submit

perhaps you can shed some light
I have stripped down the example to virtually nothing and it works great
but as i said - i am not calling the form submit if that is what is happening

thanks for your time
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35110821
Ok,

In the example below, the validate method gets the requirements for the form validation from the class and minlength setting in the input definition.

<html>
<head>
<title>a title</title>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("form").validate();
})
</script>
</head>
<body>
<form method="get" action="">
<input id="name" name="name" class="required" minlength="2" />
<input class="submit" type="submit" value="Submit"/>
</form>
</body>
</html>

alternatively you could omit the settings in the body (eg: name="name" class="required) and put it in the script like so:

$(function(){
$("form").validate(
rules: name: {
                        required: true,
                        minlength: 2
                  });
}),

the validate method detects the submit press and displays a default  error,

you can also give custom messages
Carrying on from above

messages: username: {
                        required: "Please enter your name",
                        minlength: "Your name must consist of at least 2 characters"
                  }

If you take a look in the source it gives examples with other form elements.

If you want to change the way the errors are displayed you can override the styles for text.


Darren
0
 
LVL 25

Author Comment

by:dgrafx
ID: 35110908
run the below code to see what i'm talking about

=====================
<script type="text/javascript">
$(".submit").live("click", function() {
alert();
$("form").validate();
});
</script>

<form method="get" action="">
<input id="tester" name="tester" class="required" minlength="2" /> <br>
<a href="" class="submit" onclick="return false;">Save</a>
<!--- <input class="submit" type="submit" value="Submit"/>  --->
</form>
=====================

I am NOT calling a form submit directly
I'm doing some ajax stuff
I need the fields to be validated when called by jquery - NOT from a form submit
do you know what i'm talking about?
0
 
LVL 13

Accepted Solution

by:
darren-w- earned 500 total points
ID: 35111245
this works:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>title</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
       <script type="text/javascript" src="validate.js"></script>

      <script type="text/javascript">
         $(function(){
            $(".submit").live("click", function() {
              // console.log("got here");
               $(this).parent("form").validate().form();
            });
         });
      </script>
   </head>
   <body >
      <form method="get" action="">
         <input id="tester" name="tester" class="required" minlength="2" /> <br />
            <a href="#" class="submit" onclick="return false;">Save</a>
            <!--- <input class="submit" type="submit" value="Submit"/>  --->
      </form>
   </body>
</html>

Open in new window

0
 
LVL 25

Author Comment

by:dgrafx
ID: 35111300
right on buddy - looks good!
thanks ...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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…

825 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