-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
136 lines (110 loc) · 3.76 KB
/
index.php
File metadata and controls
136 lines (110 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
require("db.inc.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$errors = [];
$success = false;
$begin = new DateTime('2025-02-06');
$end = new DateTime('2025-05-06');
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
$name = "";
$email = "";
$appdate = "";
if (isset($_POST['formSubmit'])) {
$name = $_POST['inputName'];
$email = $_POST['inputEmail'];
$appdate = $_POST['appdate'];
if (strlen($name) > 100) {
$errors[] = "Name is too long.";
}
if (strlen($name) <= 3) {
$errors[] = "Please enter your full name.";
}
if (preg_match("/[\^<,\"@\/\{\}\(\)\*\$%\?=>:\|;#]+/i", $name)) {
$errors[] = "Name cannot contain special characters.";
}
if (strlen($email) == 0) {
$errors[] = "Please enter your email address.";
}
if (strlen($email) > 100) {
$errors[] = "Email address is too long.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL) && strlen($email) > 0) {
$errors[] = "Please enter a valid email address.";
}
if ($appdate == "") {
$errors[] = "Please select a date.";
}
if (count($errors) == 0) {
$success = newAppointment(
$name,
$email,
$appdate,
);
header("Location: confirmation.php");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous" />
<title>Schedule an appointment - FELInt</title>
</head>
<body>
<div class="container">
<main>
<h2>Schedule an appointment with FELInt</h2>
<hr />
<?php if (count($errors) > 0): ?>
<div class="alert alert-danger" role="alert">
<ul>
<?php foreach ($errors as $error): ?>
<li><?= $error; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif ?>
<form method="post" action="index.php">
<div class="form-group mt-3">
<label for="inputName" class="col-sm-2 col-form-label">Name:</label>
<div>
<input type="text" class="form-control" id="inputName" name="inputName" placeholder="Display Name" value="<?php echo isset($name) ? $name : ''; ?>">
</div>
</div>
<div class="form-group mt-3">
<label for="inputEmail" class="col-sm-2 col-form-label">Email Address:</label>
<div>
<input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Email" value="<?php echo isset($email) ? $email : ''; ?>">
</div>
</div>
<div class="form-group mt-3">
<label for="appdate" class="col-sm-2 col-form-label">Appointment Date:</label>
<div>
<select name="appdate" id="appdate" class="form-select">
<option value="">Select a date</option>
<?php foreach ($period as $date): ?>
<option value="<?= $date->format('Y-m-d') ?>"><?= $date->format('l, j F Y') ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group mt-5">
<div>
<button type="submit" class="btn btn-primary" name="formSubmit" style="width: 100%">Schedule Appointment</button>
</div>
</div>
</form>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>