index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>BootstrapValidator demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
  7. <!-- Include the FontAwesome CSS if you want to use feedback icons provided by FontAwesome -->
  8. <!--<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" />-->
  9. <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
  10. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  11. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  12. </head>
  13. <body>
  14. <div class="container">
  15. <div class="row">
  16. <!-- form: -->
  17. <section>
  18. <div class="col-lg-8 col-lg-offset-2">
  19. <div class="page-header">
  20. <h2>Sign up</h2>
  21. </div>
  22. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  23. <div class="form-group">
  24. <label class="col-lg-3 control-label">Full name</label>
  25. <div class="col-lg-4">
  26. <input type="text" class="form-control" name="firstName" placeholder="First name" />
  27. </div>
  28. <div class="col-lg-4">
  29. <input type="text" class="form-control" name="lastName" placeholder="Last name" />
  30. </div>
  31. </div>
  32. <div class="form-group">
  33. <label class="col-lg-3 control-label">Username</label>
  34. <div class="col-lg-5">
  35. <input type="text" class="form-control" name="username" />
  36. </div>
  37. </div>
  38. <div class="form-group">
  39. <label class="col-lg-3 control-label">Email address</label>
  40. <div class="col-lg-5">
  41. <input type="text" class="form-control" name="email" />
  42. </div>
  43. </div>
  44. <div class="form-group">
  45. <label class="col-lg-3 control-label">Password</label>
  46. <div class="col-lg-5">
  47. <input type="password" class="form-control" name="password" />
  48. </div>
  49. </div>
  50. <div class="form-group">
  51. <label class="col-lg-3 control-label">Retype password</label>
  52. <div class="col-lg-5">
  53. <input type="password" class="form-control" name="confirmPassword" />
  54. </div>
  55. </div>
  56. <div class="form-group">
  57. <label class="col-lg-3 control-label">Gender</label>
  58. <div class="col-lg-5">
  59. <div class="radio">
  60. <label>
  61. <input type="radio" name="gender" value="male" /> Male
  62. </label>
  63. </div>
  64. <div class="radio">
  65. <label>
  66. <input type="radio" name="gender" value="female" /> Female
  67. </label>
  68. </div>
  69. <div class="radio">
  70. <label>
  71. <input type="radio" name="gender" value="other" /> Other
  72. </label>
  73. </div>
  74. </div>
  75. </div>
  76. <div class="form-group">
  77. <label class="col-lg-3 control-label">Birthday</label>
  78. <div class="col-lg-5">
  79. <input type="text" class="form-control" name="birthday" /> (YYYY/MM/DD)
  80. </div>
  81. </div>
  82. <div class="form-group">
  83. <label class="col-lg-3 control-label">Languages</label>
  84. <div class="col-lg-5">
  85. <div class="checkbox">
  86. <label>
  87. <input type="checkbox" name="languages[]" value="english" /> English
  88. </label>
  89. </div>
  90. <div class="checkbox">
  91. <label>
  92. <input type="checkbox" name="languages[]" value="french" /> French
  93. </label>
  94. </div>
  95. <div class="checkbox">
  96. <label>
  97. <input type="checkbox" name="languages[]" value="german" /> German
  98. </label>
  99. </div>
  100. <div class="checkbox">
  101. <label>
  102. <input type="checkbox" name="languages[]" value="russian" /> Russian
  103. </label>
  104. </div>
  105. <div class="checkbox">
  106. <label>
  107. <input type="checkbox" name="languages[]" value="other" /> Other
  108. </label>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="form-group">
  113. <label class="col-lg-3 control-label">Programming Languages</label>
  114. <div class="col-lg-5">
  115. <div class="checkbox">
  116. <label>
  117. <input type="checkbox" name="programs[]" value="net" /> .Net
  118. </label>
  119. </div>
  120. <div class="checkbox">
  121. <label>
  122. <input type="checkbox" name="programs[]" value="java" /> Java
  123. </label>
  124. </div>
  125. <div class="checkbox">
  126. <label>
  127. <input type="checkbox" name="programs[]" value="c" /> C/C++
  128. </label>
  129. </div>
  130. <div class="checkbox">
  131. <label>
  132. <input type="checkbox" name="programs[]" value="php" /> PHP
  133. </label>
  134. </div>
  135. <div class="checkbox">
  136. <label>
  137. <input type="checkbox" name="programs[]" value="perl" /> Perl
  138. </label>
  139. </div>
  140. <div class="checkbox">
  141. <label>
  142. <input type="checkbox" name="programs[]" value="ruby" /> Ruby
  143. </label>
  144. </div>
  145. <div class="checkbox">
  146. <label>
  147. <input type="checkbox" name="programs[]" value="python" /> Python
  148. </label>
  149. </div>
  150. <div class="checkbox">
  151. <label>
  152. <input type="checkbox" name="programs[]" value="javascript" /> Javascript
  153. </label>
  154. </div>
  155. </div>
  156. </div>
  157. <div class="form-group">
  158. <label class="col-lg-3 control-label" id="captchaOperation"></label>
  159. <div class="col-lg-2">
  160. <input type="text" class="form-control" name="captcha" />
  161. </div>
  162. </div>
  163. <div class="form-group">
  164. <div class="col-lg-9 col-lg-offset-3">
  165. <button type="submit" class="btn btn-primary" name="signup" value="Sign up">Sign up</button>
  166. <button type="submit" class="btn btn-primary" name="signup2" value="Sign up 2">Sign up 2</button>
  167. <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
  168. <button type="button" class="btn btn-info" id="resetBtn">Reset form</button>
  169. </div>
  170. </div>
  171. </form>
  172. </div>
  173. </section>
  174. <!-- :form -->
  175. </div>
  176. </div>
  177. <script type="text/javascript">
  178. $(document).ready(function() {
  179. // Generate a simple captcha
  180. function randomNumber(min, max) {
  181. return Math.floor(Math.random() * (max - min + 1) + min);
  182. };
  183. $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  184. $('#defaultForm').bootstrapValidator({
  185. // live: 'disabled',
  186. message: 'This value is not valid',
  187. feedbackIcons: {
  188. valid: 'glyphicon glyphicon-ok',
  189. invalid: 'glyphicon glyphicon-remove',
  190. validating: 'glyphicon glyphicon-refresh'
  191. },
  192. fields: {
  193. firstName: {
  194. group: '.col-lg-4',
  195. validators: {
  196. notEmpty: {
  197. message: 'The first name is required and cannot be empty'
  198. }
  199. }
  200. },
  201. lastName: {
  202. group: '.col-lg-4',
  203. validators: {
  204. notEmpty: {
  205. message: 'The last name is required and cannot be empty'
  206. }
  207. }
  208. },
  209. username: {
  210. message: 'The username is not valid',
  211. validators: {
  212. notEmpty: {
  213. message: 'The username is required and cannot be empty'
  214. },
  215. stringLength: {
  216. min: 6,
  217. max: 30,
  218. message: 'The username must be more than 6 and less than 30 characters long'
  219. },
  220. regexp: {
  221. regexp: /^[a-zA-Z0-9_\.]+$/,
  222. message: 'The username can only consist of alphabetical, number, dot and underscore'
  223. },
  224. remote: {
  225. type: 'POST',
  226. url: 'remote.php',
  227. message: 'The username is not available'
  228. },
  229. different: {
  230. field: 'password,confirmPassword',
  231. message: 'The username and password cannot be the same as each other'
  232. }
  233. }
  234. },
  235. email: {
  236. validators: {
  237. emailAddress: {
  238. message: 'The input is not a valid email address'
  239. }
  240. }
  241. },
  242. password: {
  243. validators: {
  244. notEmpty: {
  245. message: 'The password is required and cannot be empty'
  246. },
  247. identical: {
  248. field: 'confirmPassword',
  249. message: 'The password and its confirm are not the same'
  250. },
  251. different: {
  252. field: 'username',
  253. message: 'The password cannot be the same as username'
  254. }
  255. }
  256. },
  257. confirmPassword: {
  258. validators: {
  259. notEmpty: {
  260. message: 'The confirm password is required and cannot be empty'
  261. },
  262. identical: {
  263. field: 'password',
  264. message: 'The password and its confirm are not the same'
  265. },
  266. different: {
  267. field: 'username',
  268. message: 'The password cannot be the same as username'
  269. }
  270. }
  271. },
  272. birthday: {
  273. validators: {
  274. date: {
  275. format: 'YYYY/MM/DD',
  276. message: 'The birthday is not valid'
  277. }
  278. }
  279. },
  280. gender: {
  281. validators: {
  282. notEmpty: {
  283. message: 'The gender is required'
  284. }
  285. }
  286. },
  287. 'languages[]': {
  288. validators: {
  289. notEmpty: {
  290. message: 'Please specify at least one language you can speak'
  291. }
  292. }
  293. },
  294. 'programs[]': {
  295. validators: {
  296. choice: {
  297. min: 2,
  298. max: 4,
  299. message: 'Please choose 2 - 4 programming languages you are good at'
  300. }
  301. }
  302. },
  303. captcha: {
  304. validators: {
  305. callback: {
  306. message: 'Wrong answer',
  307. callback: function(value, validator) {
  308. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  309. return value == sum;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. });
  316. // Validate the form manually
  317. $('#validateBtn').click(function() {
  318. $('#defaultForm').bootstrapValidator('validate');
  319. });
  320. $('#resetBtn').click(function() {
  321. $('#defaultForm').data('bootstrapValidator').resetForm(true);
  322. });
  323. });
  324. </script>
  325. </body>
  326. </html>