Topic: Form validation not working

Porlan free asked 5 years ago


Hi!

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 = 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); })();

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.

thanks!


Piotr Glejzer staff commented 5 years ago

Hi,

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.

Best,

Piotr



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.5.10
  • Device: computer
  • Browser: chrome
  • OS: linux mint
  • Provided sample code: No
  • Provided link: No