65 lines
2.6 KiB
JavaScript
65 lines
2.6 KiB
JavaScript
const formulario = document.getElementById("formulario-datos-extendido");
|
|
const notificacion = document.getElementById("mensaje-error");
|
|
|
|
formulario.addEventListener("submit", async(event) => {
|
|
event.preventDefault();
|
|
|
|
// Limpiar mensaje de error previo
|
|
notificacion.textContent = "";
|
|
notificacion.style.display = "none";
|
|
|
|
// Obtener valores de los campos
|
|
const idCandidato = document.getElementById('id_candidato').value;
|
|
const idPais = document.getElementById('id_pais').value;
|
|
const codigoPostal = document.getElementById('codigo_postal').value; // campo numérico, no necesita trim
|
|
const idEstado = document.getElementById('id_estado').value;
|
|
const idMunicipio = document.getElementById('id_municipio').value;
|
|
const idColonia = document.getElementById('id_colonia').value;
|
|
|
|
const idNivel = document.getElementById('id_nivel').value;
|
|
const idGiro = document.getElementById('id_giro').value;
|
|
const nombreEmpresa = document.getElementById('nombre_empresa').value.trim();
|
|
const motivoExamen = document.getElementById('motivo_examen').value.trim();
|
|
|
|
const calificacionServicio = document.getElementById('calificacion_servicio').value;
|
|
const consentimientoPub = document.getElementById('consentimiento_pub').checked;
|
|
|
|
var id = 6;
|
|
|
|
// Preparar datos para envío
|
|
const formData = new FormData();
|
|
formData.append("id_candidato", id);
|
|
formData.append("id_pais", idPais);
|
|
formData.append("codigo_postal", codigoPostal);
|
|
formData.append("id_estado", idEstado);
|
|
formData.append("id_municipio", idMunicipio);
|
|
formData.append("id_colonia", idColonia);
|
|
formData.append("id_nivel", idNivel);
|
|
formData.append("id_giro", idGiro);
|
|
|
|
formData.append("nombre_empresa_institucion", nombreEmpresa);
|
|
formData.append("motivo_examen", motivoExamen);
|
|
|
|
formData.append("calificacion_servicio", calificacionServicio);
|
|
formData.append("consentimiento_pub", consentimientoPub ? 1 : 0);
|
|
|
|
try {
|
|
const respuesta = await fetch('controllers/registrarInfoCandidato.php', {
|
|
method: "POST",
|
|
body: formData,
|
|
});
|
|
|
|
const resultado = await respuesta.json();
|
|
|
|
if (resultado.registroExitoso) {
|
|
alert('Se guardó la información correctamente');
|
|
window.location.href = 'inicio.html';
|
|
} else {
|
|
notificacion.textContent = resultado.mensaje;
|
|
notificacion.style.display = "block";
|
|
}
|
|
} catch (error) {
|
|
notificacion.textContent = "Lo sentimos, ocurrió un error: " + error.message;
|
|
notificacion.style.display = "block";
|
|
}
|
|
}); |