forked from posabsolute/jQuery-Validation-Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemoAjax.html
executable file
·92 lines (88 loc) · 4.55 KB
/
demoAjax.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>JQuery Validation Engine</title>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<script src="js/jquery-1.4.4.min.js" type="text/javascript">
</script>
<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8">
</script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8">
</script>
<script>
// This method is called right before the ajax form validation request
// it is typically used to setup some visuals ("Please wait...");
// you may return a false to stop the request
function beforeCall(form, options){
if (console)
console.log("Right before the AJAX form validation call");
return true;
}
// Called once the server replies to the ajax form validation request
function ajaxValidationCallback(status, form, json, options){
if (console)
console.log(status);
if (status === true) {
alert("the form is valid!");
// uncomment these lines to submit the form to form.action
// form.validationEngine('detach');
// form.submit();
// or you may use AJAX again to submit the data
}
}
jQuery(document).ready(function(){
jQuery("#formID").validationEngine({
ajaxFormValidation: true,
onAjaxFormComplete: ajaxValidationCallback,
onBeforeAjaxFormValidation: beforeCall
});
});
</script>
</head>
<body>
<p>
<a href="#" onclick="alert(jQuery('#formID').validationEngine({evaluate:true}))">Return true or false without binding anything</a>
| <a href="#" onclick="jQuery.validationEngine.buildPrompt('#formID','This is an example','error')">Build a prompt on a div</a>
| <a href="#" onclick="jQuery.validationEngine.loadValidation('#date')">Load validation date</a>
| <a href="#" onclick="jQuery.validationEngine.closePrompt('.formError',true)">Close all prompt</a>
</p>
<p>
This demonstrations shows the use of Ajax <b>form</b>
and <b>field</b>
validations.
<br/>
The form validation implements callback hooks, so please check the javascript console
</p>
<form id="formID" class="formular" method="post" action="ajaxSubmitForm" style="width:600px">
<fieldset>
<legend>
Ajax validation
</legend>
<label>
<span>Desired username (ajax validation, only <b>karnius</b> is available) : </span>
<input value="karnius" class="validate[required,custom[onlyLetterNumber],maxSize[20],ajax[ajaxUserCall]] text-input" type="text" name="user" id="user" />
<p>
validate[required,custom[noSpecialCaracters],maxSize[20],ajax[ajaxUserCall]]
</p>
</label>
<label>
<span>First name (ajax validation, only <b>duncan</b> is available): </span>
<input value="olivier" class="validate[custom[onlyLetterSp],maxSize[100],ajax[ajaxNameCall]] text-input" type="text" name="firstname" id="firstname" />
<p>
validate[custom[onlyLetterSp],length[0,100],ajax[ajaxNameCall]]
</p>
</label>
<label>
<span>Email address : </span>
<input value="[email protected]" class="validate[required,custom[email]] text-input" type="text" name="email" id="email" />
<p>
validate[required,custom[email]]
</p>
</label>
</fieldset>
<input class="submit" type="submit" value="Validate & Send the form!"/><hr/>
</form>
</body>
</html>