@@ -9,15 +9,7 @@ particular form.
9
9
* Usage example*
10
10
11
11
``` html
12
- <html >
13
- <head >
14
- <script src =" js/jquery.min.js" ></script >
15
- <script src =" js/form-validator/jquery.form-validator.min.js" ></script >
16
- <script >
17
- $ .formUtils .loadModules (' date,security' );
18
- </script >
19
- </head >
20
- <form action =" " onsubmit =" return $(this).validate();" >
12
+ <form action =" " method =" POST" >
21
13
<p >
22
14
Name (4 characters minimum):
23
15
<input name =" user" data-validation =" length" data-validation-length =" min4" />
@@ -34,7 +26,13 @@ particular form.
34
26
<input type =" submit" />
35
27
</p >
36
28
</form >
37
- ...
29
+ <script src =" js/jquery.min.js" ></script >
30
+ <script src =" js/form-validator/jquery.form-validator.min.js" ></script >
31
+ <script >
32
+ $ .setupForm ({
33
+ modules : ' date, security'
34
+ });
35
+ </script >
38
36
```
39
37
40
38
### Moving up to version 2.0
@@ -43,9 +41,11 @@ So what has changed since version 1.x?
43
41
44
42
* A whole bunch of validation functions have been added (see below)
45
43
* A modular design have been introduced, which means that some validation functions is default and others is
46
- part of a module.
44
+ part of a module. This in turn reduces server and bandwidth costs.
47
45
* You no longer need to prefix the validation rules with "validate_ "
48
46
* Error message position now defaults to "element"
47
+ * The optional features (validatOnBlur and showHelpOnFocus) is now enabled by default
48
+ * The function $.setForm is introduced that makes it possible to initiate the form validation with less code
49
49
50
50
51
51
### Default validators and features (no module needed)
@@ -102,11 +102,17 @@ You can use the function `$.formUtils.addValidator()` to add your own validation
102
102
that checks if the input contains an even number.
103
103
104
104
``` html
105
- <html >
106
- <head >
107
- <script src =" js/jquery.min.js" ></script >
108
- <script src =" js/formvalidator/jquery.formvalidator.min.js" ></script >
109
- <script >
105
+ <form action =" " method =" post" onsubmit =" return $(this).validate();" >
106
+ <p >
107
+ <input type =" text" data-validation =" even" />
108
+ </p >
109
+ ...
110
+ </form >
111
+ <script src =" js/jquery.min.js" ></script >
112
+ <script src =" js/form-validator/jquery.form-validator.min.js" ></script >
113
+ <script >
114
+
115
+ // Add validator
110
116
$ .formUtils .addValidator ({
111
117
name : ' even' ,
112
118
validate : function (value , $el , config , language , $form ) {
@@ -115,14 +121,11 @@ that checks if the input contains an even number.
115
121
errorMessage : ' You have to answer an even number' ,
116
122
errorMessageKey: ' badEvenNumber'
117
123
});
118
- </script >
119
- </head >
120
- <body >
121
- ...
122
- <form action =" " method =" post" onsubmit =" return $(this).validate();" >
123
- <p >
124
- <input type =" text" data-validation =" even" />
125
- ...
124
+
125
+ // Initiate form validation
126
+ $ .setupForm ();
127
+
128
+ </script >
126
129
```
127
130
128
131
### Required properties passed into $.formUtils.addValidator
@@ -157,7 +160,7 @@ URL, so that the browser never caches the file. You should of course never use *
157
160
``` html
158
161
<html >
159
162
<head >
160
- <script src =" js/formvalidator /jquery.formvalidator .min.js" ></script >
163
+ <script src =" js/form-validator /jquery.form-validator .min.js" ></script >
161
164
<script >
162
165
$ .formUtils .loadModules (' mymodule.dev' , ' js/validation-modules/' );
163
166
</script >
@@ -172,23 +175,7 @@ caches the javascript).
172
175
173
176
The second argument is the path where the module files is located. This argument is optional, if not given
174
177
the module files has to be located in the same directory as the core modules shipped together with this jquery plugin
175
- (js/formvalidator/)
176
-
177
- ## Validate inputs on blur
178
- It is possible to show that the value of an input is incorrect immediately when the input gets blurred.
179
-
180
- ``` html
181
- <form action =" " onsubmit =" return $(this).validate();" id =" my_form" >
182
- <p >
183
- <strong >Website:</strong >
184
- <input type =" text" name =" website" data-validation =" url" />
185
- </p >
186
- ...
187
- </form >
188
- <script >
189
- $ (' #my_form' ).validateOnBlur ();
190
- </script >
191
- ```
178
+ (js/form-validator/)
192
179
193
180
## Show help information
194
181
It is possible to display help information for each input. The information will fade in when input is focused and fade out when input looses focus.
@@ -200,10 +187,6 @@ It is possible to display help information for each input. The information will
200
187
<textarea name =" why" data-validation-help =" Please give us some more information" data-validation =" required" ></textarea >
201
188
</p >
202
189
...
203
- </form >
204
- <script >
205
- $ (' #my_form' ).showHelpOnFocus ();
206
- </script >
207
190
```
208
191
209
192
## Fully customizable
@@ -292,61 +275,37 @@ var enErrorDialogs = {
292
275
```
293
276
294
277
``` html
295
- <html >
296
- <head >
297
- <script src =" scripts/jquery.formvalidator.min.js" ></script >
298
- <script src =" scripts/locale.en.js" ></script >
299
- ...
300
- <head >
301
- <body >
302
- ...
303
- <form action =" script.php" onsubmit =" return $(this).validate(enErrorDialogs);" >
278
+ <form action =" script.php" onsubmit =" return $(this).validate(enErrorDialogs);" >
304
279
...
305
- ```
306
-
307
- Inline error messages is also possible. If you add attribute data-validation-error-msg to an element the value of that attribute will be displayed instead of the error dialog that the validation function refers to.
308
-
309
- ## Simple captcha example
310
- ``` php
311
- <?php
312
- session_start();
313
- if( isset($_POST['captcha']) && isset($_SESSION['captcha'])) {
314
- if($_POST['captcha'] != ($_SESSION['captcha'][0]+$_SESSION['captcha'][1]))
315
- die('Invalid captcha answer'); // client does not have javascript enabled
316
- }
317
-
318
- $_SESSION['captcha'] = array( mt_rand(0,9), mt_rand(1, 9) );
319
-
320
- ?>
321
- <html >
322
- ....
323
- <form action =" " onsubmit =" return $(this).validate();" >
324
- <p >
325
- What is the sum of <?=$_SESSION['captcha'][0]?> + <?=$_SESSION['captcha'][1]?>? (security question)
326
- <input name =" captcha" data-validation =" spamcheck captcha<?=( $_SESSION['capthca'][0] + $_SESSION['captcha'][1] )?>"
327
- </p >
328
- <p ><input type =" submit" /></p >
329
280
</form >
281
+ <script src =" js/jquery.min.js" ></script >
282
+ <script src =" js/form-validator/jquery.form-validator.min.js" ></script >
283
+ <script src =" js/form-validator/locale.en.js" ></script >
284
+ <script >
285
+ $ .setupForm ({
286
+ language : enErrorDialogs
287
+ });
288
+ </script >
330
289
...
331
- </ html >
290
+
332
291
```
333
292
293
+ Inline error messages is also possible. If you add attribute data-validation-error-msg to an element the value of that attribute will be displayed instead of the error dialog that the validation function refers to.
294
+
334
295
## Input length restriction
335
296
``` html
336
297
<p >
337
298
History (<span id =" maxlength" >50</span > characters left)
338
299
<textarea rows =" 3" id =" area" ></textarea >
339
300
</p >
340
301
<script type =" text/javascript" >
341
- $ (' #area' ).restrictLength ($ (' #maxlength' ));
302
+ $ (' #area' ).restrictLength ( $ (' #maxlength' ) );
342
303
</script >
343
304
```
344
305
345
306
## Password confirmation example
346
- ``` html
347
- <p >Password: <input type =" password" name =" pass" data-validation =" confirmation" /></p >
348
- <p >Confirm password: <input type =" password" name =" pass_confirmation" /></p >
349
- ```
307
+
308
+ [ Click here for more info] ( http://formvalidator.net/#security-validators_confirmation )
350
309
351
310
## Changelog
352
311
@@ -358,15 +317,28 @@ $_SESSION['captcha'] = array( mt_rand(0,9), mt_rand(1, 9) );
358
317
* length now looks at attribute data-validation-length to find out how long or short the value must be
359
318
* The validation rule no longer needs to be prefixed with ""
360
319
* Some validation functions is moved to modules (see function reference in top of this document)
320
+ * Added function $.formSetup() to reduce the amount of code that has to be written when initiating the form validation.
321
+
322
+
323
+ ## Credits
361
324
362
- ## Maintainer
325
+ #### Maintainer
363
326
364
327
[ Victor Jonsson] ( https://github.com/victorjonsson )
365
328
366
- ## Contributors
367
- [ Joel Sutherland] ( https://github.com/robamaton ) (contributor)<br />
368
- [ Steve Wasiura] ( https://github.com/stevewasiura ) (contributor)<br />
369
- [ Matt Clements] ( https://github.com/mattclements ) (contributor)<br />
370
- [ dfcplc] ( https://github.com/dfcplc ) (contributor)<br />
371
- [ Darren Mason] ( http://www.mypocket-technologies.com ) (Password strength meter)<br />
372
- [ Scott Gonzales] ( http://projects.scottsplayground.com/iri/ ) (URL regexp)
329
+ #### Contributors
330
+ <a href =" https://github.com/robamaton " target =" _blank " >Joel Sutherland</a ><br />
331
+ <a href =" https://github.com/stevewasiura " target =" _blank " >Steve Wasiura</a ><br />
332
+ <a href =" https://github.com/mattclements " target =" _blank " >Matt Clements</a ><br />
333
+ <a href =" https://github.com/dfcplc " target =" _blank " >@dfcplc </a ><br />
334
+ <a href =" https://github.com/coffein " target =" _blank " >Andree Wendel</a ><br />
335
+ <a href =" http://www.huotmedia.com " target =" _blank " >Nicholas Huot</a ><br />
336
+ <a href =" https://github.com/Repkit " target =" _blank " >@repkit </a ><br />
337
+ <a href =" https://github.com/aL3xa " target =" _blank " >Alexandar Blagotic</a ><br />
338
+ <a href =" http://thekindof.me/ " target =" _blank " >Yasith Fernando</a ><br />
339
+ <a href =" https://github.com/S0L4R1S " target =" _blank " >@S0L4R1S </a ><br />
340
+
341
+ #### Additional credits
342
+
343
+ <a href =" http://projects.scottsplayground.com/iri/ " target =" _blank " >Scott Gonzales</a > (URL regexp)<br />
344
+ <a href =" http://www.mypocket-technologies.com " target =" _blank " >Darren Mason</a > (Password strength meter)
0 commit comments