| 1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> |
| 6 |
<title>Test for jQuery validate() plugin</title> |
| 7 |
|
| 8 |
<link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" /> |
| 9 |
|
| 10 |
<script src="../lib/jquery.js" type="text/javascript"></script> |
| 11 |
<script src="../lib/jquery.metadata.js" type="text/javascript"></script> |
| 12 |
<script src="../jquery.validate.js" type="text/javascript"></script> |
| 13 |
|
| 14 |
<script src="js/cmxforms.js" type="text/javascript"></script> |
| 15 |
<style type="text/css"> |
| 16 |
.cmxform fieldset p.error label { color: red; } |
| 17 |
div.container { |
| 18 |
background-color: #eee; |
| 19 |
border: 1px solid red; |
| 20 |
margin: 5px; |
| 21 |
padding: 5px; |
| 22 |
} |
| 23 |
div.container ol li { |
| 24 |
list-style-type: disc; |
| 25 |
margin-left: 20px; |
| 26 |
} |
| 27 |
div.container { display: none } |
| 28 |
.container label.error { |
| 29 |
display: inline; |
| 30 |
} |
| 31 |
form.cmxform { width: 30em; } |
| 32 |
form.cmxform label.error { |
| 33 |
display: block; |
| 34 |
margin-left: 1em; |
| 35 |
width: auto; |
| 36 |
} |
| 37 |
</style> |
| 38 |
|
| 39 |
<script type="text/javascript"> |
| 40 |
// only for demo purposes |
| 41 |
$.validator.setDefaults({ |
| 42 |
submitHandler: function() { |
| 43 |
alert("submitted! (skipping validation for cancel button)"); |
| 44 |
} |
| 45 |
}); |
| 46 |
|
| 47 |
$().ready(function() { |
| 48 |
$("#form1").validate({ |
| 49 |
errorLabelContainer: $("#form1 div.error") |
| 50 |
}); |
| 51 |
|
| 52 |
var container = $('div.container'); |
| 53 |
// validate the form when it is submitted |
| 54 |
var validator = $("#form2").validate({ |
| 55 |
errorContainer: container, |
| 56 |
errorLabelContainer: $("ol", container), |
| 57 |
wrapper: 'li', |
| 58 |
meta: "validate" |
| 59 |
}); |
| 60 |
|
| 61 |
$(".cancel").click(function() { |
| 62 |
validator.resetForm(); |
| 63 |
}); |
| 64 |
}); |
| 65 |
</script> |
| 66 |
|
| 67 |
</head> |
| 68 |
<body> |
| 69 |
|
| 70 |
<h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jQuery Validation Plugin</a> Demo</h1> |
| 71 |
<div id="main"> |
| 72 |
|
| 73 |
<form method="get" class="cmxform" id="form1" action=""> |
| 74 |
<fieldset> |
| 75 |
<legend>Login Form</legend> |
| 76 |
<p> |
| 77 |
<label>Username</label> |
| 78 |
<input name="user" title="Please enter your username (at least 3 characters)" class="{required:true,minlength:3}" /> |
| 79 |
</p> |
| 80 |
<p> |
| 81 |
<label>Password</label> |
| 82 |
<input type="password" maxlength="12" name="password" title="Please enter your password, between 5 and 12 characters" class="{required:true,minlength:5}" /> |
| 83 |
</p> |
| 84 |
<div class="error"> |
| 85 |
</div> |
| 86 |
<p> |
| 87 |
<input class="submit" type="submit" value="Login"/> |
| 88 |
</p> |
| 89 |
</fieldset> |
| 90 |
</form> |
| 91 |
|
| 92 |
<!-- our error container --> |
| 93 |
<div class="container"> |
| 94 |
<h4>There are serious errors in your form submission, please see below for details.</h4> |
| 95 |
<ol> |
| 96 |
<li><label for="email" class="error">Please enter your email address</label></li> |
| 97 |
<li><label for="phone" class="error">Please enter your phone <b>number</b> (between 2 and 8 characters)</label></li> |
| 98 |
<li><label for="address" class="error">Please enter your address (at least 3 characters)</label></li> |
| 99 |
<li><label for="avatar" class="error">Please select an image (png, jpg, jpeg, gif)</label></li> |
| 100 |
<li><label for="cv" class="error">Please select a document (doc, docx, txt, pdf)</label></li> |
| 101 |
</ol> |
| 102 |
</div> |
| 103 |
|
| 104 |
<form class="cmxform" id="form2" method="get" action=""> |
| 105 |
<fieldset> |
| 106 |
<legend>Validating a complete form</legend> |
| 107 |
<p> |
| 108 |
<label for="email">Email</label> |
| 109 |
<input id="email" name="email" class="{validate:{required:true,email:true}}" /> |
| 110 |
</p> |
| 111 |
<p> |
| 112 |
<label for="agree">Favorite Color</label> |
| 113 |
<select id="color" name="color" title="Please select your favorite color!" class="{validate:{required:true}}"> |
| 114 |
<option></option> |
| 115 |
<option>Red</option> |
| 116 |
<option>Blue</option> |
| 117 |
<option>Yellow</option> |
| 118 |
</select> |
| 119 |
</p> |
| 120 |
<p> |
| 121 |
<label for="phone">Phone</label> |
| 122 |
<input id="phone" name="phone" class="some styles {validate:{required:true,number:true, rangelength:[2,8]}}" /> |
| 123 |
</p> |
| 124 |
<p> |
| 125 |
<label for="address">Address</label> |
| 126 |
<input id="address" name="address" class="some other styles {validate:{required:true,minlength:3}}" /> |
| 127 |
</p> |
| 128 |
<p> |
| 129 |
<label for="avatar">Avatar</label> |
| 130 |
<input type="file" id="avatar" name="avatar" class="{validate:{required:true,accept:true}}" /> |
| 131 |
</p> |
| 132 |
<p> |
| 133 |
<label for="agree">Please agree to our policy</label> |
| 134 |
<input type="checkbox" class="checkbox" id="agree" title="Please agree to our policy!" name="agree" class="{validate:{required:true}}" /> |
| 135 |
</p> |
| 136 |
<p> |
| 137 |
<label for="cv">CV</label> |
| 138 |
<input type="file" id="cv" name="cv" class="{validate:{required:true,accept:'docx?|txt|pdf'}}" /> |
| 139 |
</p> |
| 140 |
<p> |
| 141 |
<input class="submit" type="submit" value="Submit"/> |
| 142 |
<input class="cancel" type="submit" value="Cancel"/> |
| 143 |
</p> |
| 144 |
</fieldset> |
| 145 |
</form> |
| 146 |
|
| 147 |
<div class="container"> |
| 148 |
<h4>There are serious errors in your form submission, please see details above the form!</h4> |
| 149 |
</div> |
| 150 |
|
| 151 |
<a href="index.html">Back to main page</a> |
| 152 |
|
| 153 |
</div> |
| 154 |
|
| 155 |
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> |
| 156 |
</script> |
| 157 |
<script type="text/javascript"> |
| 158 |
_uacct = "UA-2623402-1"; |
| 159 |
urchinTracker(); |
| 160 |
</script> |
| 161 |
</body> |
| 162 |
</html> |