1<script>
2 // Example starter JavaScript for disabling form submissions if there are invalid fields
3 (function() {
4 'use strict';
5 window.addEventListener('load', function() {
6 // Fetch all the forms we want to apply custom Bootstrap validation styles to
7 var forms = document.getElementsByClassName('needs-validation');
8 // Loop over them and prevent submission
9 var validation = Array.prototype.filter.call(forms, function(form) {
10 form.addEventListener('submit', function(event) {
11 if (form.checkValidity() === false) {
12 event.preventDefault();
13 event.stopPropagation();
14 }
15 form.classList.add('was-validated');
16 }, false);
17 });
18 }, false);
19 })();
20 </script>
1<form>
2 <div class="form-row">
3 <div class="col-md-4 mb-3">
4 <label for="validationServer01">First name</label>
5 <input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="Mark" required>
6 <div class="valid-feedback">
7 Looks good!
8 </div>
9 </div>
10 <div class="col-md-4 mb-3">
11 <label for="validationServer02">Last name</label>
12 <input type="text" class="form-control is-valid" id="validationServer02" placeholder="Last name" value="Otto" required>
13 <div class="valid-feedback">
14 Looks good!
15 </div>
16 </div>
17 <div class="col-md-4 mb-3">
18 <label for="validationServerUsername">Username</label>
19 <div class="input-group">
20 <div class="input-group-prepend">
21 <span class="input-group-text" id="inputGroupPrepend3">@</span>
22 </div>
23 <input type="text" class="form-control is-invalid" id="validationServerUsername" placeholder="Username" aria-describedby="inputGroupPrepend3" required>
24 <div class="invalid-feedback">
25 Please choose a username.
26 </div>
27 </div>
28 </div>
29 </div>
30 <div class="form-row">
31 <div class="col-md-6 mb-3">
32 <label for="validationServer03">City</label>
33 <input type="text" class="form-control is-invalid" id="validationServer03" placeholder="City" required>
34 <div class="invalid-feedback">
35 Please provide a valid city.
36 </div>
37 </div>
38 <div class="col-md-3 mb-3">
39 <label for="validationServer04">State</label>
40 <input type="text" class="form-control is-invalid" id="validationServer04" placeholder="State" required>
41 <div class="invalid-feedback">
42 Please provide a valid state.
43 </div>
44 </div>
45 <div class="col-md-3 mb-3">
46 <label for="validationServer05">Zip</label>
47 <input type="text" class="form-control is-invalid" id="validationServer05" placeholder="Zip" required>
48 <div class="invalid-feedback">
49 Please provide a valid zip.
50 </div>
51 </div>
52 </div>
53 <div class="form-group">
54 <div class="form-check">
55 <input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" required>
56 <label class="form-check-label" for="invalidCheck3">
57 Agree to terms and conditions
58 </label>
59 <div class="invalid-feedback">
60 You must agree before submitting.
61 </div>
62 </div>
63 </div>
64 <button class="btn btn-primary" type="submit">Submit form</button>
65</form>
1function form_validate(attr_id){
2 var result = true;
3 $('#'+attr_id).validator('validate');
4 $('#'+attr_id+' .form-group').each(function(){
5 if($(this).hasClass('has-error')){
6 result = false;
7 return false;
8 }
9 });
10 return result;
11}
12