submitHandler.html 4.6 KB

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