$(document).ready(function () {
var formularioVersion = $("#formulario-version").val();
$.ajax({
url: "https://api.eqamexico.com/api/fields",
type: "GET",
data: { value: formularioVersion },
success: function (response) {
const data = typeof response === 'string' ? JSON.parse(response) : response;
function llenarSelect(select, opciones) {
$.each(opciones, function (key, value) {
select.append($('', {
value: key,
text: value
}));
});
}
data.opciones?.Interesado && llenarSelect($("#interes"), data.opciones.Interesado);
data.opciones?.Certificacion && llenarSelect($("#certificacion"), data.opciones.Certificacion);
data.opciones?.Capacitacion && llenarSelect($("#certificacion"), data.opciones.Capacitacion);
},
error: function (xhr, status, error) {
console.error("Error al enviar la solicitud:", xhr.status, error);
}
});
function getUTMParams() {
var params = {
utm_source: "",
utm_medium: "",
utm_campaign: "",
utm_id: "",
utm_term: "",
utm_content: ""
};
var url = new URL(window.location.href);
url.searchParams.forEach(function (value, key) {
if (key.startsWith('utm_')) {
params[key] = value;
}
});
return params;
}
$('#contacto-form').submit(function (event) {
event.preventDefault();
$('.btn-form').hide();
$('#loader').show();
var formData = {
interes: $('#interes').val(),
certificacion: $('#certificacion').val(),
estado_sg: $('#estado_sg').val(),
nombre: $('#nombre').val(),
apellido: $('#apellido').val(),
correo: $('#correo').val(),
telefono: $('#telefono').val(),
empresa: $('#empresa').val(),
puesto: $('#puesto').val(),
ciudad: $('#ciudad').val(),
pais: $('#pais').val(),
comoSeEntero: $('#comoSeEntero').val(),
mensaje: $('#mensaje').val(),
pagina_origen: window.location.href
};
var utmParams = getUTMParams();
formData = { ...formData, ...utmParams };
$.ajax({
url: 'https://api.eqamexico.com/api/contact',
type: 'POST',
data: formData,
success: function (response) {
const data = typeof response === 'string' ? JSON.parse(response) : response;
$('#nombre').val('');
$('#apellido').val('');
$('#correo').val('');
$('#telefono').val('');
$('#empresa').val('');
$('#puesto').val('');
$('#ciudad').val('');
$('#mensaje').val('');
if (data.code === 200) {
window.location.href = 'https://eqamexico.com/gracias/';
}
},
error: function (xhr, status, error) {
console.error('Error al enviar la solicitud:', error);
$('#mensaje').after('
Hubo un error al enviar el formulario. Inténtalo de nuevo más tarde.
');
$('#loader').hide();
$('.btn-form').show();
}
});
});
});