prepare("SELECT title, description, starts_at, ends_at FROM webinars WHERE id = ?"); $stmt->execute([$webinar_id]); $webinar = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { // Log error, but don't show to user } } // --- FORM SUBMISSION (POST REQUEST) --- if ($_SERVER["REQUEST_METHOD"] == "POST") { header('Content-Type: application/json'); // --- DATA CAPTURE --- $webinar_id = filter_input(INPUT_POST, 'webinar_id', FILTER_VALIDATE_INT); // --- WEBINAR DETAILS --- $webinar = null; if ($webinar_id) { try { // Fetch webinar details to create calendar links $stmt = $pdo->prepare("SELECT title, description, starts_at, ends_at FROM webinars WHERE id = ?"); $stmt->execute([$webinar_id]); $webinar = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { // Log error, but don't show to user } } $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING); $last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING); $company = filter_input(INPUT_POST, 'company', FILTER_SANITIZE_STRING); $how_did_you_hear = filter_input(INPUT_POST, 'how_did_you_hear', FILTER_SANITIZE_STRING); $password = filter_input(INPUT_POST, 'password', FILTER_UNSAFE_RAW); $confirm_password = filter_input(INPUT_POST, 'confirm_password', FILTER_UNSAFE_RAW); $consent = filter_input(INPUT_POST, 'consent', FILTER_VALIDATE_BOOLEAN); $timezone = filter_input(INPUT_POST, 'timezone', FILTER_SANITIZE_STRING); // Tracking data $utm_source = filter_input(INPUT_POST, 'utm_source', FILTER_SANITIZE_STRING); $utm_medium = filter_input(INPUT_POST, 'utm_medium', FILTER_SANITIZE_STRING); $utm_campaign = filter_input(INPUT_POST, 'utm_campaign', FILTER_SANITIZE_STRING); $utm_term = filter_input(INPUT_POST, 'utm_term', FILTER_SANITIZE_STRING); $utm_content = filter_input(INPUT_POST, 'utm_content', FILTER_SANITIZE_STRING); $referrer = filter_input(INPUT_POST, 'referrer', FILTER_SANITIZE_STRING); $gclid = filter_input(INPUT_POST, 'gclid', FILTER_SANITIZE_STRING); $fbclid = filter_input(INPUT_POST, 'fbclid', FILTER_SANITIZE_STRING); if (!$first_name || !$last_name || !$email) { $response['error'] = 'Please fill out all required fields.'; echo json_encode($response); exit; } if (!$consent || !$webinar) { $response['error'] = 'Please agree to the terms.'; echo json_encode($response); exit; } if ($password !== $confirm_password) { $response['error'] = 'Passwords do not match.'; echo json_encode($response); exit; } $password_hash = password_hash($password, PASSWORD_DEFAULT); try { // Check for duplicates $stmt = db()->prepare("SELECT id FROM attendees WHERE webinar_id = ? AND email = ?"); $stmt->execute([$webinar_id, $email]); if ($stmt->fetch()) { $response['error'] = 'You are already registered for this webinar.'; echo json_encode($response); exit; } // Insert attendee $sql = "INSERT INTO attendees (webinar_id, first_name, last_name, email, company, how_did_you_hear, password, timezone, utm_source, utm_medium, utm_campaign, utm_term, utm_content, referrer, gclid, fbclid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = db()->prepare($sql); $stmt->execute([$webinar_id, $first_name, $last_name, $email, $company, $how_did_you_hear, $password_hash, $timezone, $utm_source, $utm_medium, $utm_campaign, $utm_term, $utm_content, $referrer, $gclid, $fbclid]); $attendee_id = db()->lastInsertId(); // --- SEND CONFIRMATION EMAIL --- $webinar_date = new DateTime($webinar['starts_at']); $subject = "Confirmation: You're Registered for " . $webinar['title']; $body_html = "

You're in!

" . "

Thanks for registering for our webinar: {$webinar['title']}.

" . "

It will take place on " . $webinar_date->format('l, F j, Y \a\t g:i A T') . ".

" . "

You can now log in to your dashboard to see the details.

"; MailService::sendMail($email, $subject, $body_html); $response['success'] = true; $response['webinar_title'] = $webinar['title']; $response['webinar_date_utc'] = $webinar['starts_at']; } catch (PDOException $e) { // Log error $response['error'] = 'A database error occurred. Please try again later.'; } catch (Exception $e) { // Log error $response['error'] = 'An error occurred: ' . $e->getMessage(); } echo json_encode($response); exit; } // --- RENDER PAGE (GET REQUEST) --- if (!$webinar) { http_response_code(404); echo "Webinar not found."; exit; } ?> Register for <?= htmlspecialchars($webinar['title']) ?>
Back to Home

Loading date...

Speakers

Philip Daineka Philip Daineka
Alex Rubanau Alex Rubanau
Alexey Vertel Alexey Vertel

Register & Get Calendar Invite

We’ll send the join link & calendar invite.

No spam. Unsubscribe anytime.