-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Develop JavaScript for Form Validation #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| document.addEventListener('DOMContentLoaded', function() { | ||||||||||||||||||||||||||||||||||||||||||||
| document.getElementById('settings').addEventListener('submit', function(event) { | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| document.getElementById('settings').addEventListener('submit', function(event) { | |
| let settingsForm = document.getElementById('settings'); | |
| if (!settingsForm) { | |
| return; | |
| } | |
| settingsForm.addEventListener('submit', function(event) { |
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handler assumes the #settings form has inputs named name, last, email, user, and password (e.g., event.target.name.value). In this repo, id="settings" is reused on many unrelated forms, so submitting those forms would throw. Scope the listener to the intended form(s) (unique id/class/data-attr) or check form.elements[...] exist before accessing .value.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces ES6+ features (let, arrow functions, template literals, NodeList.forEach) while the rest of the repo JS (e.g., jscripts/cpanel.js) is written in older ES3/ES5 style. If legacy browsers are in scope for this project, this may break at runtime; consider rewriting in ES5-compatible syntax or ensuring a build/transpile step exists.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showError() looks for elements with ids like errormsg_name/errormsg_email, but the existing forms currently render <span class="errormsg" id="errormsg_0">... (same id for all fields), so users will get blocked submission with no visible error. Update the selector/markup so the JS can reliably find the correct error element for each field (or fall back to the nearest .errormsg next to the input).
| let errorSpan = document.querySelector(`.errormsg[id='errormsg_${field}']`); | |
| let errorSpan = document.querySelector(`.errormsg[id='errormsg_${field}']`); | |
| if (!errorSpan) { | |
| let fieldInput = event.target.elements[field]; | |
| if (fieldInput) { | |
| if (fieldInput.nextElementSibling && fieldInput.nextElementSibling.classList.contains('errormsg')) { | |
| errorSpan = fieldInput.nextElementSibling; | |
| } else if (fieldInput.parentElement) { | |
| errorSpan = fieldInput.parentElement.querySelector('.errormsg'); | |
| if (!errorSpan && fieldInput.closest) { | |
| let fieldContainer = fieldInput.closest('label, div, p, td, li, .form-group, .field'); | |
| if (fieldContainer) { | |
| errorSpan = fieldContainer.querySelector('.errormsg'); | |
| } | |
| } | |
| } | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn’t referenced by
includes/header.phpor any page template in the repo (no<script src="jscripts/formValidation.js">occurrences), so the validation will never run as-is. Ensure it’s included on the relevant pages (and only those pages, given the#settingsid reuse).