34950-vm/register.php
Flatlogic Bot dbf75ca780 1 version
2025-10-16 14:27:03 +00:00

191 lines
6.1 KiB
PHP

<?php
declare(strict_types=1);
require_once 'db/config.php';
$pdo = db();
$webinar_id = filter_input(INPUT_GET, 'webinar_id', FILTER_VALIDATE_INT);
$webinar = null;
$feedback = [];
// Fetch webinar details
if ($webinar_id) {
try {
$stmt = $pdo->prepare('SELECT id, title, scheduled_at FROM webinars WHERE id = ?');
$stmt->execute([$webinar_id]);
$webinar = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
error_log("Webinar fetch error: " . $e->getMessage());
// Don't expose error details to user
}
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$email = filter_var(trim($_POST['email'] ?? ''), FILTER_VALIDATE_EMAIL);
$submitted_webinar_id = filter_input(INPUT_POST, 'webinar_id', FILTER_VALIDATE_INT);
if (!$name || !$email || !$submitted_webinar_id) {
$feedback = ['type' => 'error', 'message' => 'Please fill in all fields with valid information.'];
} else {
try {
$stmt = $pdo->prepare('INSERT INTO attendees (webinar_id, name, email) VALUES (?, ?, ?)');
$stmt->execute([$submitted_webinar_id, $name, $email]);
$feedback = ['type' => 'success', 'message' => 'Thank you for registering! A confirmation has been sent to your email.'];
// In a real app, you would trigger an email here.
} catch (PDOException $e) {
error_log("Registration error: " . $e->getMessage());
if ($e->errorInfo[1] == 1062) { // Duplicate entry
$feedback = ['type' => 'error', 'message' => 'This email address has already been registered for this webinar.'];
} else {
$feedback = ['type' => 'error', 'message' => 'An error occurred during registration. Please try again.'];
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Register for Webinar</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color: #1A2035;
--primary-color: #F2A900;
--text-color: #FFFFFF;
--card-bg: #2A3045;
--error-color: #E57373;
--success-color: #81C784;
}
body {
margin: 0;
font-family: 'Poppins', sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
max-width: 500px;
width: 100%;
padding: 2rem;
}
.form-container {
background: var(--card-bg);
padding: 2.5rem;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}
h1 {
text-align: center;
font-size: 2rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--primary-color);
}
.webinar-info {
text-align: center;
margin-bottom: 2rem;
color: #E0E0E0;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
}
input[type="text"], input[type="email"] {
width: 100%;
padding: 0.8rem;
border: 1px solid #4A5062;
border-radius: 8px;
background-color: var(--bg-color);
color: var(--text-color);
font-family: 'Poppins', sans-serif;
box-sizing: border-box;
}
.submit-btn {
width: 100%;
padding: 0.9rem;
border: none;
border-radius: 8px;
background-color: var(--primary-color);
color: var(--bg-color);
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
}
.submit-btn:hover {
background-color: #FFC107;
}
.feedback {
padding: 1rem;
margin-bottom: 1.5rem;
border-radius: 8px;
text-align: center;
}
.feedback.success {
background-color: var(--success-color);
color: #1B5E20;
}
.feedback.error {
background-color: var(--error-color);
color: #C62828;
}
.back-link {
display: block;
text-align: center;
margin-top: 2rem;
color: var(--primary-color);
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<div class="form-container">
<?php if ($feedback && $feedback['type'] === 'success'): ?>
<h1>Registration Successful!</h1>
<div class="feedback success"><?= htmlspecialchars($feedback['message']) ?></div>
<a href="index.php" class="back-link">&larr; Back to Webinars</a>
<?php elseif ($webinar): ?>
<h1>Register for Webinar</h1>
<p class="webinar-info">You are registering for: <strong><?= htmlspecialchars($webinar['title']) ?></strong></p>
<?php if ($feedback && $feedback['type'] === 'error'): ?>
<div class="feedback error"><?= htmlspecialchars($feedback['message']) ?></div>
<?php endif; ?>
<form action="register.php?webinar_id=<?= $webinar_id ?>" method="POST">
<input type="hidden" name="webinar_id" value="<?= $webinar_id ?>">
<div class="form-group">
<label for="name">Full Name</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" required>
</div>
<button type="submit" class="submit-btn">Register Now</button>
</form>
<a href="index.php" class="back-link">&larr; Cancel</a>
<?php else: ?>
<h1>Webinar Not Found</h1>
<p style="text-align:center">The requested webinar could not be found.</p>
<a href="index.php" class="back-link">&larr; Back to Webinars</a>
<?php endif; ?>
</div>
</div>
</body>
</html>