58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
// Basic validation
|
|
$name = trim($_POST['name'] ?? '');
|
|
$companyName = trim($_POST['companyName'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$phone = trim($_POST['phone'] ?? '');
|
|
$potentialAmount = $_POST['potentialAmount'] ?? null;
|
|
|
|
if (empty($name) || empty($email)) {
|
|
$_SESSION['error_message'] = 'Name and Email are required.';
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$_SESSION['error_message'] = 'Invalid email format.';
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
if ($potentialAmount !== null && !is_numeric($potentialAmount)) {
|
|
$_SESSION['error_message'] = 'Potential amount must be a number.';
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare(
|
|
'INSERT INTO leads (Name, CompanyName, Email, Phone, PotentialAmount, Status) VALUES (?, ?, ?, ?, ?, ?)'
|
|
);
|
|
$stmt->execute([
|
|
$name,
|
|
$companyName,
|
|
$email,
|
|
$phone,
|
|
$potentialAmount,
|
|
'New' // Default status
|
|
]);
|
|
|
|
$_SESSION['success_message'] = 'Lead added successfully!';
|
|
|
|
} catch (PDOException $e) {
|
|
// In a real app, log this error.
|
|
$_SESSION['error_message'] = 'Failed to add lead. Please try again.';
|
|
}
|
|
|
|
header('Location: index.php');
|
|
exit();
|