x
This commit is contained in:
@@ -45,6 +45,7 @@ function enviar() {
|
|||||||
'content' => http_build_query($data)
|
'content' => http_build_query($data)
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$context = stream_context_create($options);
|
$context = stream_context_create($options);
|
||||||
$result = file_get_contents($verifyUrl, false, $context);
|
$result = file_get_contents($verifyUrl, false, $context);
|
||||||
$response = json_decode($result);
|
$response = json_decode($result);
|
||||||
@@ -53,43 +54,32 @@ function enviar() {
|
|||||||
die("❌ Error de verificación reCAPTCHA.");
|
die("❌ Error de verificación reCAPTCHA.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$conn = getConnection();
|
$conn = getConnection();
|
||||||
|
|
||||||
$empresa = encrypt($_POST['company_name'] ?? '');
|
$empresa = encrypt(trim($_POST['company_name'] ?? ''));
|
||||||
$rfc = encrypt($_POST['rfc'] ?? '');
|
$rfc = strtoupper(encrypt(trim($_POST['rfc'] ?? '')));
|
||||||
$email = $_POST['email'] ?? '';
|
$email = trim($_POST['email'] ?? '');
|
||||||
$telefono = $_POST['phone'] ?? '';
|
$telefono = trim($_POST['phone'] ?? '');
|
||||||
$archivo = $_FILES['opinion_file'];
|
$archivo = $_FILES['opinion_file'];
|
||||||
|
|
||||||
// Validar RFC
|
// Validar RFC (12 o 13 caracteres con formato correcto)
|
||||||
if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/i', $_POST['rfc'] ?? '')) {
|
if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/', strtoupper($_POST['rfc'] ?? ''))) {
|
||||||
die("RFC inválido. Debe seguir el formato oficial.");
|
die("❌ El RFC no tiene un formato válido.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validar el Email (minúsculas + dominio @empresa.com)
|
// Validar email (solo minúsculas, sin caracteres especiales fuera del estándar)
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (!preg_match('/^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) {
|
||||||
die("No es una dirección de correo válida.");
|
die("❌ No es una dirección de correo válida.");
|
||||||
}
|
|
||||||
if (!preg_match('/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) {
|
|
||||||
die("No es una dirección de correo.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validar el Teléfono: debe tener formato 3 dígitos + espacio + 7 dígitos
|
// Validar teléfono (formato nacional: 3 dígitos + espacio + 7 dígitos)
|
||||||
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
|
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
|
||||||
die("El teléfono debe tener el formato 3 dígitos, espacio, 7 dígitos (ej. 123 4567890).");
|
die("❌ El número de teléfono no tiene un formato válido. Ejemplo: 123 4567890");
|
||||||
}
|
|
||||||
|
|
||||||
// También podemos validar que tenga exactamente 10 dígitos sin espacios
|
|
||||||
$soloDigitos = str_replace(' ', '', $telefono);
|
|
||||||
if (!ctype_digit($soloDigitos) || strlen($soloDigitos) !== 10) {
|
|
||||||
die("El teléfono debe contener exactamente 10 dígitos numéricos.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validar archivo
|
// Validar archivo
|
||||||
if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') {
|
if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') {
|
||||||
die("Archivo inválido. Solo se permiten PDFs.");
|
die("❌ Archivo inválido. Solo se permiten PDFs.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title><?= htmlspecialchars($siglas) ?> | Registro de Importador</title>
|
<title><?= htmlspecialchars($siglas) ?> | Registro de Importador</title>
|
||||||
@@ -67,7 +68,8 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-control, .form-select {
|
.form-control,
|
||||||
|
.form-select {
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<!-- Navbar institucional -->
|
<!-- Navbar institucional -->
|
||||||
@@ -157,57 +160,6 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
|
||||||
document.getElementById("formRegistro").addEventListener("submit", function(event) {
|
|
||||||
const rfcInput = document.querySelector('input[name="rfc"]');
|
|
||||||
const emailInput = document.querySelector('input[name="email"]');
|
|
||||||
const phoneInput = document.querySelector('input[name="phone"]');
|
|
||||||
|
|
||||||
const rfc = rfcInput.value.toUpperCase();
|
|
||||||
const email = emailInput.value.trim();
|
|
||||||
const phone = phoneInput.value.trim();
|
|
||||||
|
|
||||||
// Validación RFC
|
|
||||||
const rfcRegex = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/;
|
|
||||||
if (!rfcRegex.test(rfc)) {
|
|
||||||
alert("RFC inválido. Asegúrate de que siga el formato correcto.");
|
|
||||||
rfcInput.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
rfcInput.value = rfc; // Convertir a mayúsculas
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validación correo - solo minúsculas y con cualquier dominio
|
|
||||||
const correoRegex = /^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
|
|
||||||
if (!correoRegex.test(email)) {
|
|
||||||
e.preventDefault(); // Detiene el envío del formulario
|
|
||||||
alert("No es una dirección de correo válida (solo minúsculas, sin acentos ni caracteres especiales).");
|
|
||||||
emailInput.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validación teléfono
|
|
||||||
const phoneRegex = /^\d{3}\s\d{7}$/;
|
|
||||||
if (!phoneRegex.test(phone)) {
|
|
||||||
alert("El teléfono debe tener el formato 3 dígitos, espacio, 7 dígitos (ej. 123 4567890)");
|
|
||||||
phoneInput.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validación de solo números sin espacios para verificación
|
|
||||||
const digitsOnly = phone.replace(/\s/g, "");
|
|
||||||
if (digitsOnly.length !== 10 || isNaN(digitsOnly)) {
|
|
||||||
alert("El teléfono debe contener exactamente 10 dígitos numéricos.");
|
|
||||||
phoneInput.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -228,15 +180,53 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
<!-- Validación JS -->
|
<!-- Validación JS -->
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('formRegistro').addEventListener('submit', function(e) {
|
document.getElementById('formRegistro').addEventListener('submit', function(e) {
|
||||||
|
const rfcInput = document.querySelector('input[name="rfc"]');
|
||||||
|
const emailInput = document.querySelector('input[name="email"]');
|
||||||
|
const phoneInput = document.querySelector('input[name="phone"]');
|
||||||
const archivo = document.getElementById('opinion_file').files[0];
|
const archivo = document.getElementById('opinion_file').files[0];
|
||||||
const recaptcha = grecaptcha.getResponse();
|
const recaptcha = grecaptcha.getResponse();
|
||||||
|
|
||||||
|
const rfc = rfcInput.value.trim().toUpperCase();
|
||||||
|
const email = emailInput.value.trim();
|
||||||
|
const phone = phoneInput.value.trim();
|
||||||
|
|
||||||
|
// Expresiones regulares
|
||||||
|
const correoRegex = /^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
|
||||||
|
const rfcRegex = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/;
|
||||||
|
const telefonoRegex = /^\d{3}\s\d{7}$/;
|
||||||
|
|
||||||
|
// Validación de correo
|
||||||
|
if (!correoRegex.test(email)) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire("Correo inválido", "No es una dirección de correo válida. Solo se permiten minúsculas.", "error");
|
||||||
|
emailInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de RFC
|
||||||
|
if (!rfcRegex.test(rfc)) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire("RFC inválido", "El RFC debe tener 12 o 13 caracteres con el formato correcto (ej. ABC123456XYZ).", "error");
|
||||||
|
rfcInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de teléfono
|
||||||
|
if (!telefonoRegex.test(phone)) {
|
||||||
|
e.preventDefault();
|
||||||
|
Swal.fire("Teléfono inválido", "Debe tener 10 dígitos en el formato: 3 dígitos (LADA), espacio, y 7 dígitos. Ejemplo: 123 4567890", "error");
|
||||||
|
phoneInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validación de archivo PDF
|
||||||
if (!archivo || archivo.type !== 'application/pdf') {
|
if (!archivo || archivo.type !== 'application/pdf') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Swal.fire("Error", "Solo se permite subir archivos PDF.", "error");
|
Swal.fire("Error", "Solo se permite subir archivos PDF.", "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validación de reCAPTCHA
|
||||||
if (recaptcha.length === 0) {
|
if (recaptcha.length === 0) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Swal.fire("Verificación requerida", "Por favor completa el reCAPTCHA.", "warning");
|
Swal.fire("Verificación requerida", "Por favor completa el reCAPTCHA.", "warning");
|
||||||
@@ -246,4 +236,5 @@ $color2 = explode(',', $config['colores_primarios'] ?? '#003366,#0055A5')
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user