x
This commit is contained in:
@@ -23,74 +23,64 @@ loadEnv();
|
||||
|
||||
|
||||
function enviar() {
|
||||
// Validar reCAPTCHA
|
||||
$captchaResponse = $_POST['g-recaptcha-response'] ?? '';
|
||||
// Validar reCAPTCHA
|
||||
$captchaResponse = $_POST['g-recaptcha-response'] ?? '';
|
||||
|
||||
if (!$captchaResponse) {
|
||||
die("❌ Debes completar el reCAPTCHA.");
|
||||
}
|
||||
if (!$captchaResponse) {
|
||||
die("❌ Debes completar el reCAPTCHA.");
|
||||
}
|
||||
|
||||
$secretKey = $_ENV['RECAPTCHA_SECRET'];
|
||||
$secretKey = $_ENV['RECAPTCHA_SECRET'];
|
||||
|
||||
$verifyUrl = "https://www.google.com/recaptcha/api/siteverify";
|
||||
$data = [
|
||||
'secret' => $secretKey,
|
||||
'response' => $captchaResponse
|
||||
];
|
||||
$verifyUrl = "https://www.google.com/recaptcha/api/siteverify";
|
||||
$data = [
|
||||
'secret' => $secretKey,
|
||||
'response' => $captchaResponse
|
||||
];
|
||||
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
||||
'method' => 'POST',
|
||||
'content' => http_build_query($data)
|
||||
]
|
||||
];
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($verifyUrl, false, $context);
|
||||
$response = json_decode($result);
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
||||
'method' => 'POST',
|
||||
'content' => http_build_query($data)
|
||||
]
|
||||
];
|
||||
|
||||
if (!$response->success) {
|
||||
die("❌ Error de verificación reCAPTCHA.");
|
||||
}
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($verifyUrl, false, $context);
|
||||
$response = json_decode($result);
|
||||
|
||||
if (!$response->success) {
|
||||
die("❌ Error de verificación reCAPTCHA.");
|
||||
}
|
||||
|
||||
$conn = getConnection();
|
||||
|
||||
$conn = getConnection();
|
||||
$empresa = encrypt(trim($_POST['company_name'] ?? ''));
|
||||
$rfc = strtoupper(encrypt(trim($_POST['rfc'] ?? '')));
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$telefono = trim($_POST['phone'] ?? '');
|
||||
$archivo = $_FILES['opinion_file'];
|
||||
|
||||
$empresa = encrypt($_POST['company_name'] ?? '');
|
||||
$rfc = encrypt($_POST['rfc'] ?? '');
|
||||
$email = $_POST['email'] ?? '';
|
||||
$telefono = $_POST['phone'] ?? '';
|
||||
$archivo = $_FILES['opinion_file'];
|
||||
// Validar RFC (12 o 13 caracteres con formato correcto)
|
||||
if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/', strtoupper($_POST['rfc'] ?? ''))) {
|
||||
die("❌ El RFC no tiene un formato válido.");
|
||||
}
|
||||
|
||||
// Validar RFC
|
||||
if (!preg_match('/^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/i', $_POST['rfc'] ?? '')) {
|
||||
die("RFC inválido. Debe seguir el formato oficial.");
|
||||
}
|
||||
// Validar email (solo minúsculas, sin caracteres especiales fuera del estándar)
|
||||
if (!preg_match('/^[a-z0-9._+-]+@[a-z0-9.-]+\.[a-z]{2,}$/', $email)) {
|
||||
die("❌ No es una dirección de correo válida.");
|
||||
}
|
||||
|
||||
// Validar el Email (minúsculas + dominio @empresa.com)
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
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 teléfono (formato nacional: 3 dígitos + espacio + 7 dígitos)
|
||||
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
|
||||
die("❌ El número de teléfono no tiene un formato válido. Ejemplo: 123 4567890");
|
||||
}
|
||||
|
||||
// Validar el Teléfono: debe tener formato 3 dígitos + espacio + 7 dígitos
|
||||
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).");
|
||||
}
|
||||
|
||||
// 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
|
||||
if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') {
|
||||
die("Archivo inválido. Solo se permiten PDFs.");
|
||||
}
|
||||
// Validar archivo
|
||||
if ($archivo['error'] !== 0 || pathinfo($archivo['name'], PATHINFO_EXTENSION) !== 'pdf') {
|
||||
die("❌ Archivo inválido. Solo se permiten PDFs.");
|
||||
}
|
||||
|
||||
|
||||
// Guardar archivo
|
||||
|
||||
Reference in New Issue
Block a user