Form validation not working

Topic: Form validation not working

Porlan pro premium asked a week ago


I'm trying to validate a form. In my jquery file I'm using this code:

(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 =, function(form) { form.addEventListener('submit', function(event) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } form.classList.add('was-validated'); }, false); }); }, false); })();

The form is submitting instead it's not valid. The invalid-feedback errors appers but then the browser submits form.

I would like to know how to call an Ajax to php function, and use it only with one form insted of a loop with all forms in the page.


Piotr Glejzer commented a week ago


it's probably not working cause you need some PHP functions and callbacks with that. Do you have some PHP files or anything what can you include to Ajax with PHP? Have a nice day.



Please insert min. 20 characters.


Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: jQuery
  • MDB Version: 4.5.10
  • Device: computer
  • Browser: chrome
  • OS: linux mint
  • Provided sample code: No
  • Provided link: No