function validateConcertForm() { var artista = document.getElementById('artista').value.trim(); var fecha = document.getElementById('fecha').value.trim(); var lugar = document.getElementById('lugar').value.trim(); var precio = document.getElementById('precio').value.trim(); if (!artista || !fecha || !lugar || !precio) { alert("Por favor, completa todos los campos."); return false; } // 🔸 Validación adicional de la fecha var fechaEvento = new Date(fecha); var ahora = new Date(); if (fechaEvento <= ahora) { alert("No puedes crear eventos con fechas anteriores o iguales a la fecha y hora actual."); return false; } return true; } function enviarFormulario(event) { event.preventDefault(); if (!validateConcertForm()) return; let confirmacion = confirm("¿Estás seguro de que quieres crear este evento?"); if (confirmacion) { var formData = new FormData(document.getElementById("crearConciertoForm")); fetch("controladores/crear-evento.php", { method: "POST", body: formData, credentials: 'include' }) .then(response => response.json()) .then(data => { document.getElementById("mensaje").textContent = data.mensaje || "Respuesta inesperada del servidor."; if (data.mensaje) { document.getElementById("crearConciertoForm").reset(); } }) .catch(error => { console.error("Error en la solicitud:", error); alert("Error al enviar el formulario."); }); } } document.addEventListener("DOMContentLoaded", function() { document.getElementById("crearConciertoForm").addEventListener("submit", enviarFormulario); });