Cambios edición de información

This commit is contained in:
2025-05-21 12:11:22 -06:00
parent d10d68f607
commit 69784f8bf2

View File

@@ -76,6 +76,10 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';
border-radius: 12px;
}
label {font-weight: bold;}
.error-msg {
color: red;
font-size: 0.9em;
}
</style>
</head>
<body>
@@ -88,9 +92,9 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';
<label class="col-md-2 col-form-label">Clave:</label>
<div class="col-md-3">
<input type="text" name="clave" maxlength="8"
pattern="[A-Z0-9]{8}" title="Debe contener 8 caracteres"
class="form-control" value="<?= htmlspecialchars($datos['clave'] ?? '') ?>"
onfocus="this.value=''" onblur="if(this.value=='') this.value='<?= htmlspecialchars($datos['clave'] ?? '') ?>'">
<span id="error-clave" class="error-msg"></span>
</div>
<div class="col-md-1"></div>
@@ -121,10 +125,9 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';
<label class="col-md-1 col-form-label">CURP:</label>
<div class="col-md-5">
<input type="text" name="curp" maxlength="18"
pattern="[A-Z]{4}\d{6}[MH](AS|BC|BS|CC|CL|CM|CS|CH|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS)[A-Z]{3}[A-Z0-9]{2}"
title="CURP no válido. Ejemplo: ABCD001122HCHLRS08"
class="form-control" value="<?= htmlspecialchars($datos['curp'] ?? '') ?>"
onfocus="this.value=''" onblur="if(this.value=='') this.value='<?= htmlspecialchars($datos['curp'] ?? '') ?>'">
<span id="error-curp" class="error-msg"></span>
</div>
</div>
@@ -211,9 +214,9 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';
<label class="col-md-1 col-form-label">Fax:</label>
<div class="col-md-3">
<input type="text" name="fax" maxlength="12"
pattern="\d{3} \d{3} \d{4}" title="Formato válido: 123 456 7890"
class="form-control" value="<?= htmlspecialchars($datos['fax'] ?? '') ?>"
onfocus="this.value=''" onblur="if(this.value=='') this.value='<?= htmlspecialchars($datos['fax'] ?? '') ?>'">
<span id="error-fax" class="error-msg"></span>
</div>
</div>
@@ -240,35 +243,45 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
document.getElementById('form-edicion').addEventListener('submit', function (event) {
const clave = document.querySelector('[name="clave"]').value.trim();
const curp = document.querySelector('[name="curp"]').value.trim();
const fax = document.querySelector('[name="fax"]').value.trim();
document.getElementById('form-edicion').addEventListener('submit', function (event) {
event.preventDefault(); // Evita que el formulario se envíe
let errores = [];
const clave = document.querySelector('[name="clave"]').value.trim();
const curp = document.querySelector('[name="curp"]').value.trim();
const fax = document.querySelector('[name="fax"]').value.trim();
// Validación Clave: 8 caracteres, letras y números, mayúsculas
if (!/^[A-Z0-9]{8}$/.test(clave)) {
errores.push("La clave debe tener exactamente 8 caracteres, solo letras mayúsculas y números.");
}
let errores = [];
// Validación CURP
if (!/^[A-Z]{4}[0-9]{6}[HM](AS|BC|BS|CC|CL|CM|CS|CH|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS)[A-Z]{3}[A-Z0-9]{2}$/.test(curp)) {
errores.push("La CURP no tiene el formato correcto.");
}
// Validación Clave
if (!/^[A-Z0-9]{8}$/.test(clave)) {
errores.push('La clave debe tener exactamente 8 caracteres, solo letras mayúsculas y números.');
}
// Validación Fax: 123 456 7890
if (!/^\d{3} \d{3} \d{4}$/.test(fax)) {
errores.push("El número de fax debe tener el formato: 123 456 7890.");
}
// Validación CURP
if (!/^[A-Z]{4}[0-9]{6}[HM](AS|BC|BS|CC|CL|CM|CS|CH|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS)[A-Z]{3}[A-Z0-9]{2}$/.test(curp)) {
errores.push('La CURP no tiene el formato correcto.');
}
// Si hay errores, evita que se envíe el formulario y muestra alertas
if (errores.length > 0) {
event.preventDefault();
alert(errores.join("\n"));
}
});
// Validación Fax
if (!/^\d{3} \d{3} \d{4}$/.test(fax)) {
errores.push('El número de fax debe tener el formato: 123 456 7890.');
}
// Si hay errores, mostrar alerta y no enviar
if (errores.length > 0) {
Swal.fire({
icon: 'error',
title: 'Errores en el formulario',
html: errores.map(e => `<p>${e}</p>`).join('')
});
return; // Evita que el formulario se envíe
}
// Si no hay errores, enviar el formulario
this.submit(); // Esto sí lo envía manualmente
});
</script>
</body>