removed ajax form handling for login

This commit is contained in:
Felix Ivo 2025-06-16 14:22:51 +02:00
parent cb7d71f4a7
commit 75742157b7

View File

@ -58,12 +58,6 @@ document.addEventListener('DOMContentLoaded', () => {
if(passwordInput.value) passwordInput.dispatchEvent(new Event('input')); if(passwordInput.value) passwordInput.dispatchEvent(new Event('input'));
} }
// --- AJAX Form Submissions ---
handleAjaxForm('login-form');
handleAjaxForm('register-form');
handleAjaxForm('note-form');
handleAjaxForm('logout-form'); // Added for logout
// --- Delete Note Confirmation and AJAX --- // --- Delete Note Confirmation and AJAX ---
document.querySelectorAll('.delete-note-btn').forEach(button => { document.querySelectorAll('.delete-note-btn').forEach(button => {
button.addEventListener('click', function(e) { button.addEventListener('click', function(e) {
@ -188,60 +182,6 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}); // End DOMContentLoaded }); // End DOMContentLoaded
function handleAjaxForm(formId) { // Removed successRedirectPage, rely on JSON
const form = document.getElementById(formId);
if (form) {
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(form);
const action = formData.get('action'); // Get action from FormData
if (action === 'register') {
const password = formData.get('password');
const confirmPassword = formData.get('confirm_password');
if (password !== confirmPassword) {
displayMessage('Passwords do not match.', 'danger');
return;
}
let criteriaMet = 0;
const criteriaElements = document.querySelectorAll('#password-strength ul li');
criteriaElements.forEach(li => {
if (li.classList.contains('valid')) {
criteriaMet++;
}
});
if (criteriaMet < criteriaElements.length) { // Check if all criteria are met
displayMessage('Password does not meet all requirements.', 'danger');
return;
}
}
fetch('index.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.message) { // Display message if provided
displayMessage(data.message, data.success ? 'success' : 'danger');
}
if (data.success && data.redirect) {
setTimeout(() => { window.location.href = data.redirect; }, data.message ? 1000 : 0); // Delay if message shown
} else if (data.success && (action === 'create_note' || action === 'update_note')) {
// Specific redirect for note actions if not overridden by data.redirect
setTimeout(() => { window.location.href = 'index.php?page=dashboard'; }, data.message ? 1000 : 0);
}
})
.catch(error => {
console.error('Error:', error);
displayMessage('A network error occurred. Please try again.', 'danger');
});
});
}
}
function displayMessage(message, type = 'info') { function displayMessage(message, type = 'info') {
const existingAlert = document.querySelector('#alert-container .alert'); const existingAlert = document.querySelector('#alert-container .alert');
if (existingAlert) { if (existingAlert) {