• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

form validation

i need a simple form validator
it must be able to be called with a click event

thanks
0
dgrafx
Asked:
dgrafx
  • 6
  • 5
1 Solution
 
darren-w-Commented:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/

can help with your script if required...
0
 
dgrafxAuthor Commented:
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
 
darren-w-Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dgrafxAuthor Commented:
sounds good - I'll try it
so do you have some on page code (example)?
0
 
ccwill88Commented:
0
 
dgrafxAuthor Commented:
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
 
darren-w-Commented:
Here are some demo's:

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

with further examples at the bottom of this page

0
 
dgrafxAuthor Commented:
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
 
darren-w-Commented:
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
 
dgrafxAuthor Commented:
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
 
darren-w-Commented:
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
 
dgrafxAuthor Commented:
right on buddy - looks good!
thanks ...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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