Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Display Form Validation Feedback in Tooltip Style</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="m-4"> <form action="/examples/actions/confirmation.php" class="needs-validation" method="post" novalidate> <div class="mb-3 position-relative"> <label class="form-label" for="inputEmail">Email</label> <input type="email" class="form-control" id="inputEmail" placeholder="Email" required> <div class="invalid-tooltip">Please enter a valid email address.</div> </div> <div class="mb-3 position-relative"> <label class="form-label" for="inputPassword">Password</label> <input type="password" class="form-control" id="inputPassword" placeholder="Password" required> <div class="invalid-tooltip">Please enter your password to continue.</div> </div> <div class="mb-3"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="checkRemember"> <label class="form-check-label" for="checkRemember">Remember me</label> </div> </div> <button type="submit" class="btn btn-primary">Sign in</button> </form> <!-- JavaScript for disabling form submissions if there are invalid fields --> <script> // Self-executing function (function() { 'use strict'; window.addEventListener('load', function() { // Fetch all the forms we want to apply custom Bootstrap validation styles to var forms = document.getElementsByClassName('needs-validation'); // Loop over them and prevent submission var validation = Array.prototype.filter.call(forms, function(form) { form.addEventListener('submit', function(event) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } form.classList.add('was-validated'); }, false); }); }, false); })(); </script> </div> </body> </html>