submitHandler.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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" action="target.php">
  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. live: 'disabled',
  56. feedbackIcons: {
  57. valid: 'glyphicon glyphicon-ok',
  58. invalid: 'glyphicon glyphicon-remove',
  59. validating: 'glyphicon glyphicon-refresh'
  60. },
  61. submitHandler: function(validator, form, submitButton) {
  62. // validator is the BootstrapValidator instance
  63. // form is the jQuery object present the current form
  64. form.find('.alert').html('Thanks for signing up. Now you can sign in as ' + validator.getFieldElements('username').val()).show();
  65. },
  66. fields: {
  67. username: {
  68. message: 'The username is not valid',
  69. validators: {
  70. notEmpty: {
  71. message: 'The username is required and can\'t be empty'
  72. },
  73. stringLength: {
  74. min: 6,
  75. max: 30,
  76. message: 'The username must be more than 6 and less than 30 characters long'
  77. },
  78. remote: {
  79. url: 'remote.php',
  80. message: 'The username is not available'
  81. },
  82. regexp: {
  83. regexp: /^[a-zA-Z0-9_\.]+$/,
  84. message: 'The username can only consist of alphabetical, number, dot and underscore'
  85. }
  86. }
  87. },
  88. email: {
  89. validators: {
  90. notEmpty: {
  91. message: 'The email address is required and can\'t be empty'
  92. },
  93. emailAddress: {
  94. message: 'The input is not a valid email address'
  95. }
  96. }
  97. },
  98. password: {
  99. validators: {
  100. notEmpty: {
  101. message: 'The password is required and can\'t be empty'
  102. }
  103. }
  104. }
  105. }
  106. });
  107. });
  108. </script>
  109. </body>
  110. </html>