<?php
require_once __DIR__ . '/../includes/api-helpers.php';
api_require_post();
if (api_is_spam()) api_json(true, 'Thank you! The brochure will be emailed to you shortly.');

$name = api_str('name', 120);
$email = api_str('email', 160);
$phone = api_str('phone', 40);
$developmentName = api_str('development_name', 180);

if ($name === '' || !api_valid_email($email)) {
    api_json(false, 'Please fill in your name and a valid email.');
}

$message = "Brochure request for: $developmentName";

$stmt = db()->prepare('INSERT INTO leads (type, name, email, phone, message) VALUES (?, ?, ?, ?, ?)');
$stmt->execute(['brochure', $name, $email, $phone, $message]);

api_json(true, 'Thank you! Our team will email you the brochure for "' . $developmentName . '" within 24 hours.');
