feat: form submission handler with email + WhatsApp notifications

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Gestoría LP
2026-03-02 00:11:42 +00:00
parent aacdcb92f7
commit 0ef344b67a
3 changed files with 158 additions and 0 deletions

View File

@@ -1222,6 +1222,51 @@ select.form-control {
margin-bottom: var(--space-xs); margin-bottom: var(--space-xs);
} }
/* ============================================================
Confirmation Page
============================================================ */
.confirmation-section {
display: flex;
align-items: center;
justify-content: center;
min-height: 60vh;
padding-top: 120px;
}
.confirmation-card {
text-align: center;
max-width: 500px;
margin: 0 auto;
padding: var(--space-3xl);
background: var(--color-white);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-lg);
}
.confirmation-card__icon {
font-size: 4rem;
color: var(--color-success);
margin-bottom: var(--space-lg);
}
.confirmation-card h1 {
color: var(--color-primary);
margin-bottom: var(--space-md);
}
.confirmation-card p {
color: var(--color-gray-600);
margin-bottom: var(--space-sm);
}
.confirmation-card__actions {
margin-top: var(--space-xl);
display: flex;
flex-direction: column;
gap: var(--space-md);
align-items: center;
}
/* ============================================================ /* ============================================================
Scroll Animations Scroll Animations
============================================================ */ ============================================================ */

35
confirmacion.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
session_start();
$whatsappLink = $_SESSION['whatsapp_link'] ?? null;
$nombre = $_SESSION['confirmacion_nombre'] ?? '';
$servicioNombre = $_SESSION['confirmacion_servicio'] ?? '';
// Clear confirmation data
unset($_SESSION['whatsapp_link'], $_SESSION['confirmacion_nombre'], $_SESSION['confirmacion_servicio']);
$pageTitle = 'Solicitud Enviada';
require_once __DIR__ . '/includes/header.php';
?>
<section class="section confirmation-section">
<div class="container">
<div class="confirmation-card">
<div class="confirmation-card__icon">
<i class="fas fa-check-circle"></i>
</div>
<h1>¡Solicitud enviada!</h1>
<p>Gracias <strong><?= htmlspecialchars($nombre) ?></strong>, hemos recibido tu solicitud para <strong><?= htmlspecialchars($servicioNombre) ?></strong>.</p>
<p>Nos pondremos en contacto contigo lo antes posible.</p>
<div class="confirmation-card__actions">
<?php if ($whatsappLink): ?>
<a href="<?= htmlspecialchars($whatsappLink) ?>" target="_blank" class="btn btn--whatsapp">
<i class="fab fa-whatsapp"></i> Enviar mensaje por WhatsApp
</a>
<?php endif; ?>
<a href="index.php" class="btn btn--secondary">Volver al inicio</a>
</div>
</div>
</div>
</section>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

78
formulario.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/csrf.php';
require_once __DIR__ . '/includes/mailer.php';
require_once __DIR__ . '/includes/servicios-data.php';
session_start();
// Only POST
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: index.php');
exit;
}
// CSRF check
if (!csrfValidate()) {
die('Token de seguridad inválido. Por favor regrese e intente de nuevo.');
}
// Sanitize common fields
$nombre = trim(htmlspecialchars($_POST['nombre'] ?? '', ENT_QUOTES, 'UTF-8'));
$telefono = trim(htmlspecialchars($_POST['telefono'] ?? '', ENT_QUOTES, 'UTF-8'));
$email = trim(filter_var($_POST['email'] ?? '', FILTER_SANITIZE_EMAIL));
$servicio = trim($_POST['servicio'] ?? '');
if (!$nombre || !$telefono || !isset($SERVICIOS[$servicio])) {
die('Datos incompletos. Por favor regrese y llene todos los campos requeridos.');
}
// Collect service-specific fields
$datosExtra = [];
foreach ($SERVICIOS[$servicio]['campos_formulario'] as $campo) {
$val = trim($_POST[$campo['name']] ?? '');
if ($campo['required'] && !$val) {
die('Por favor llene el campo: ' . htmlspecialchars($campo['label']));
}
$datosExtra[$campo['label']] = $val;
}
// Insert into DB
$db = getDB();
$stmt = $db->prepare('INSERT INTO solicitudes (nombre, telefono, email, servicio, datos_formulario, estado) VALUES (?, ?, ?, ?, ?, "nueva")');
$stmt->execute([$nombre, $telefono, $email, $servicio, json_encode($datosExtra, JSON_UNESCAPED_UNICODE)]);
// Send email notification
$servicioNombre = $SERVICIOS[$servicio]['nombre'];
$emailBody = "<div style='font-family:Arial,sans-serif;max-width:600px;margin:0 auto;'>";
$emailBody .= "<div style='background:#1B3A5C;color:white;padding:20px;text-align:center;'>";
$emailBody .= "<h1 style='margin:0;'>Nueva Solicitud</h1></div>";
$emailBody .= "<div style='padding:20px;border:1px solid #ddd;'>";
$emailBody .= "<h2 style='color:#1B3A5C;'>{$servicioNombre}</h2>";
$emailBody .= "<table style='width:100%;border-collapse:collapse;'>";
$emailBody .= "<tr><td style='padding:8px;border-bottom:1px solid #eee;font-weight:bold;width:40%;'>Nombre:</td><td style='padding:8px;border-bottom:1px solid #eee;'>" . htmlspecialchars($nombre) . "</td></tr>";
$emailBody .= "<tr><td style='padding:8px;border-bottom:1px solid #eee;font-weight:bold;'>Teléfono:</td><td style='padding:8px;border-bottom:1px solid #eee;'>" . htmlspecialchars($telefono) . "</td></tr>";
$emailBody .= "<tr><td style='padding:8px;border-bottom:1px solid #eee;font-weight:bold;'>Email:</td><td style='padding:8px;border-bottom:1px solid #eee;'>" . htmlspecialchars($email ?: 'No proporcionado') . "</td></tr>";
$emailBody .= "</table>";
$emailBody .= "<h3 style='color:#1B3A5C;margin-top:20px;'>Datos del trámite</h3>";
$emailBody .= "<table style='width:100%;border-collapse:collapse;'>";
foreach ($datosExtra as $label => $val) {
$emailBody .= "<tr><td style='padding:8px;border-bottom:1px solid #eee;font-weight:bold;width:40%;'>" . htmlspecialchars($label) . ":</td><td style='padding:8px;border-bottom:1px solid #eee;'>" . htmlspecialchars($val ?: 'N/A') . "</td></tr>";
}
$emailBody .= "</table>";
$emailBody .= "<p style='color:#888;font-size:12px;margin-top:20px;'>Recibido el " . date('d/m/Y \a \l\a\s H:i') . "</p>";
$emailBody .= "</div></div>";
sendEmail("Nueva solicitud: {$servicioNombre} - {$nombre}", $emailBody);
// Build WhatsApp link and store in session
$whatsappLink = buildWhatsAppLink($servicioNombre, $nombre, $telefono);
$_SESSION['whatsapp_link'] = $whatsappLink;
$_SESSION['confirmacion_nombre'] = $nombre;
$_SESSION['confirmacion_servicio'] = $servicioNombre;
// Regenerate CSRF token
unset($_SESSION['csrf_token']);
header('Location: confirmacion.php');
exit;