35286-vm/subscribe-step2.php
Flatlogic Bot 6e132e0b38 0.2
2025-10-27 21:34:11 +00:00

169 lines
8.6 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['personal_details'])) {
header('Location: subscribe.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_SESSION['insurance_details'] = [
'insuranceType' => filter_input(INPUT_POST, 'insuranceType', FILTER_SANITIZE_STRING),
'carMake' => filter_input(INPUT_POST, 'carMake', FILTER_SANITIZE_STRING),
'carModel' => filter_input(INPUT_POST, 'carModel', FILTER_SANITIZE_STRING),
'carYear' => filter_input(INPUT_POST, 'carYear', FILTER_SANITIZE_STRING),
'healthDependents' => filter_input(INPUT_POST, 'healthDependents', FILTER_SANITIZE_NUMBER_INT),
'lifeCoverage' => filter_input(INPUT_POST, 'lifeCoverage', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION),
'homeType' => filter_input(INPUT_POST, 'homeType', FILTER_SANITIZE_STRING),
];
header('Location: subscribe-step3.php');
exit;
}
$car_data = require __DIR__ . '/config/car_data.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Subscribe - SecureLife</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
<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=Inter:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<header class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">SecureLife</a>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card shadow-sm border-0" style="border-radius: 0.75rem;">
<div class="card-body p-5">
<h1 class="card-title text-center mb-2 fw-bold">Choose Your Coverage</h1>
<p class="text-center text-muted mb-5">Step 2: Select your insurance plan and details</p>
<form action="subscribe-step2.php" method="POST">
<div class="mb-4">
<label for="insuranceType" class="form-label fs-5">Insurance Type</label>
<select class="form-select form-select-lg" id="insuranceType" name="insuranceType" required>
<option value="" selected disabled>-- Select an insurance type --</option>
<option value="Car">Car Insurance</option>
<option value="Health">Health Insurance</option>
<option value="Life">Life Insurance</option>
<option value="Home">Home Insurance</option>
</select>
</div>
<div id="carFields" class="dynamic-fields d-none border-top pt-4 mt-4">
<div class="mb-3">
<label for="carMake" class="form-label">Car Make</label>
<select class="form-select" id="carMake" name="carMake">
<option value="" selected disabled>-- Select Make --</option>
<?php foreach (array_keys($car_data) as $make): ?>
<option value="<?php echo $make; ?>"><?php echo $make; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="carModel" class="form-label">Car Model</label>
<select class="form-select" id="carModel" name="carModel" disabled>
<option value="" selected disabled>-- Select Model --</option>
</select>
</div>
<div class="mb-3">
<label for="carYear" class="form-label">Year of Manufacture</label>
<input type="date" class="form-control" id="carYear" name="carYear">
</div>
</div>
<div id="healthFields" class="dynamic-fields d-none border-top pt-4 mt-4">
<div class="mb-3">
<label for="healthDependents" class="form-label">Number of Dependents</label>
<input type="number" class="form-control" id="healthDependents" name="healthDependents" placeholder="e.g., 2">
</div>
</div>
<div id="lifeFields" class="dynamic-fields d-none border-top pt-4 mt-4">
<div class="mb-3">
<label for="lifeCoverage" class="form-label">Desired Coverage Amount ($)</label>
<input type="number" class="form-control" id="lifeCoverage" name="lifeCoverage" step="1000" placeholder="e.g., 500000">
</div>
</div>
<div id="homeFields" class="dynamic-fields d-none border-top pt-4 mt-4">
<div class="mb-3">
<label for="homeType" class="form-label">Property Type</label>
<select class="form-select" id="homeType" name="homeType">
<option value="House">House</option>
<option value="Apartment">Apartment</option>
<option value="Condo">Condo</option>
</select>
</div>
</div>
<div class="d-flex justify-content-between mt-5">
<a href="subscribe.php" class="btn btn-secondary btn-lg">&larr; Go Back</a>
<button type="submit" class="btn btn-primary-modern btn-lg">Next Step &rarr;</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<footer class="text-center py-4 mt-auto bg-dark text-white">
<p class="mb-0">&copy; <?php echo date("Y"); ?> SecureLife. All Rights Reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
const carData = <?php echo json_encode($car_data); ?>;
document.getElementById('insuranceType').addEventListener('change', function () {
document.querySelectorAll('.dynamic-fields').forEach(function (el) {
el.classList.add('d-none');
});
var selectedType = this.value;
if (selectedType) {
var fieldsetId = selectedType.toLowerCase() + 'Fields';
var fieldset = document.getElementById(fieldsetId);
if (fieldset) {
fieldset.classList.remove('d-none');
}
}
});
document.getElementById('carMake').addEventListener('change', function() {
const carModelSelect = document.getElementById('carModel');
const selectedMake = this.value;
// Clear existing options
carModelSelect.innerHTML = '<option value="" selected disabled>-- Select Model --</option>';
if (selectedMake && carData[selectedMake]) {
carModelSelect.disabled = false;
carData[selectedMake].forEach(function(model) {
const option = document.createElement('option');
option.value = model;
option.textContent = model;
carModelSelect.appendChild(option);
});
} else {
carModelSelect.disabled = true;
}
});
</script>
</body>
</html>