submitHandler.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Submit Handler Demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
  7. <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
  8. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  9. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <div class="row">
  14. <!-- form: -->
  15. <section>
  16. <div class="col-lg-8 col-lg-offset-2">
  17. <div class="page-header">
  18. <h2>Custom submit handler</h2>
  19. </div>
  20. <form id="defaultForm" method="post" class="form-horizontal">
  21. <div class="alert alert-success" style="display: none;"></div>
  22. <div class="form-group">
  23. <label class="col-lg-3 control-label">Username</label>
  24. <div class="col-lg-5">
  25. <input type="text" class="form-control" name="username" />
  26. </div>
  27. </div>
  28. <div class="form-group">
  29. <label class="col-lg-3 control-label">Email address</label>
  30. <div class="col-lg-5">
  31. <input type="text" class="form-control" name="email" />
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <label class="col-lg-3 control-label">Password</label>
  36. <div class="col-lg-5">
  37. <input type="password" class="form-control" name="password" />
  38. </div>
  39. </div>
  40. <div class="form-group">
  41. <div class="col-lg-9 col-lg-offset-3">
  42. <button type="submit" class="btn btn-primary">Sign up</button>
  43. </div>
  44. </div>
  45. </form>
  46. </div>
  47. </section>
  48. <!-- :form -->
  49. </div>
  50. </div>
  51. <script type="text/javascript">
  52. $(document).ready(function() {
  53. $('#defaultForm').bootstrapValidator({
  54. message: 'This value is not valid',
  55. submitHandler: function(validator, form) {
  56. // validator is the BootstrapValidator instance
  57. // form is the jQuery object present the current form
  58. form.find('.alert').html('Thanks for signing up. Now you can sign in as ' + validator.getFieldElement('username').val()).show();
  59. },
  60. fields: {
  61. username: {
  62. message: 'The username is not valid',
  63. validators: {
  64. notEmpty: {
  65. message: 'The username is required and can\'t be empty'
  66. },
  67. stringLength: {
  68. min: 6,
  69. max: 30,
  70. message: 'The username must be more than 6 and less than 30 characters long'
  71. },
  72. regexp: {
  73. regexp: /^[a-zA-Z0-9_\.]+$/,
  74. message: 'The username can only consist of alphabetical, number, dot and underscore'
  75. }
  76. }
  77. },
  78. email: {
  79. validators: {
  80. notEmpty: {
  81. message: 'The email address is required and can\'t be empty'
  82. },
  83. emailAddress: {
  84. message: 'The input is not a valid email address'
  85. }
  86. }
  87. },
  88. password: {
  89. validators: {
  90. notEmpty: {
  91. message: 'The password is required and can\'t be empty'
  92. }
  93. }
  94. }
  95. }
  96. });
  97. });
  98. </script>
  99. </body>
  100. </html>