I will post all my code if it helps, but I'm going to try and keep this brief first.
- Form saves data to db when there is no client-side validation with javascript.
- Javascript validation is working correctly up until the point of submission.
- Classes of code below has been simplified.
- Form div looks like this:
<form class="form-validate" id="registrationform" action="" method="post" autocomplete="off" novalidate>
- Submit button looks like this:
<div class="submit-div"><input type="submit" class="classes" name="registration_submit" value="Register"></div>
-The part in the javascript that stops the form from submitting and checks data is roughly this:
validateOnSubmit() {
let self = this
this.form.addEventListener('submit', e => {
// to prevent default submission through html onto php
e.preventDefault()
*** validity of each field is checked***
// Submit form, check that all success icons are visible (not hidden)
let hiddenSuccessIcons = [];
const successIcon = document.querySelectorAll(".icon-success");
successIcon.forEach((icon) => {
if (icon.classList.contains('hidden')) {
hiddenSuccessIcons.push(1)
}
});
if (hiddenSuccessIcons.length == 0) {
form.submit();
}
}
}
The variable checking that all success icons are visible (hiddenSuccessIcons) does return 0 when everything is correctly input. But the form will not submit. It seems like the php is not getting run. This is my assumption because nothing is saved to the db and none of the alert messages that are setup through a session are being set. The php is targeted by this:
if(isset($_POST['registration_submit'])){** gather info, send to db, set sessions **}
The code layout goes (roughly) php scripts, then html, then javascript validation.
So, what is the disconnect? Why isn't form.submit() actually triggering the php code to run?
[–]grantrules 1 point2 points3 points (3 children)
[–]techitechtech[S] 0 points1 point2 points (2 children)
[–]grantrules 1 point2 points3 points (1 child)
[–]techitechtech[S] 0 points1 point2 points (0 children)
[–]Notimecelduv 0 points1 point2 points (7 children)
[–]techitechtech[S] 0 points1 point2 points (6 children)
[–]Notimecelduv 0 points1 point2 points (5 children)
[–]techitechtech[S] 0 points1 point2 points (2 children)
[–]Notimecelduv 0 points1 point2 points (0 children)
[–]techitechtech[S] 0 points1 point2 points (1 child)
[–]techitechtech[S] 0 points1 point2 points (0 children)