Changes in code after first review from Google AI Studio
This commit is contained in:
1 parent
63d160f484
commit
bc95b632f7
6 files changed
+39
-11
No files matched your search
+25
-6
@@ -136,6 +136,9 @@ function setupContactForm() {
|
||||
|
||||
const fields = Array.from(form.querySelectorAll("[data-required], [type='email']"));
|
||||
const status = form.querySelector("[data-form-status]");
|
||||
const action = (form.getAttribute("action") || "").trim();
|
||||
const hasExternalEndpoint = /^https?:\/\//i.test(action);
|
||||
const hasPlaceholderEndpoint = action.includes("YOUR_ID_HERE");
|
||||
|
||||
const validators = {
|
||||
email: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
|
||||
@@ -209,14 +212,30 @@ function setupContactForm() {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (status) {
|
||||
status.textContent = "Thanks. Your message structure is validated and ready for backend integration.";
|
||||
status.classList.add("is-success");
|
||||
status.classList.remove("is-success");
|
||||
}
|
||||
|
||||
form.reset();
|
||||
fields.forEach((field) => setFieldError(field, ""));
|
||||
if (!hasExternalEndpoint || hasPlaceholderEndpoint) {
|
||||
event.preventDefault();
|
||||
|
||||
if (status) {
|
||||
status.textContent = hasPlaceholderEndpoint
|
||||
? "Replace the Formspree form ID to enable live message delivery."
|
||||
: "Thanks. Your message structure is validated and ready for backend integration.";
|
||||
status.classList.toggle("is-success", !hasPlaceholderEndpoint);
|
||||
}
|
||||
|
||||
if (!hasPlaceholderEndpoint) {
|
||||
form.reset();
|
||||
fields.forEach((field) => setFieldError(field, ""));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
status.textContent = "Submitting your message...";
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user