Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
92 lines (89 loc) · 3.25 KB
/
Copy pathindex.php
File metadata and controls
92 lines (89 loc) · 3.25 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
<?php include 'inc/header.php';?>
<?php
$name = $email = $body = '';
$nameErr = $emailErr = $bodyErr = '';
// Form submit
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['body'];
// Validate name
if (empty($_POST['name'])) {
$nameErr = 'Name is required';
} else {
$name = $_POST['name'];
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zàèòùšđčćžA-ZŠĐČĆŽ\s]*$/", $name)) {
$name_error = "Name and surname can only contain letters and a space!";
}
}
// Validate email
if (empty($_POST['email'])) {
$emailErr = 'Email is required';
} else {
$email = $_POST['email'];
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = 'The e-mail address is not valid!';
}
}
// Validate body
if (empty($_POST['body'])) {
$bodyErr = 'Feedback is required';
} else {
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zàèòùšđčćžA-ZŠĐČĆŽ0-9 ,.!?\'\"]*$/", $body)) {
$bodyErr = "Feedback content cannot be special characters!";
}
}
if (empty($nameErr) && empty($emailErr) && empty($bodyErr)) {
// add to database
$sql = "INSERT INTO feedback (name, email, body) VALUES ('$name', '$email', '$body')";
if (mysqli_query($conn, $sql)) {
// success
echo "<script>
window.location = \"https://feedback.mirnesglamocic.com/feedback.html\"
</script>";
} else {
// error
echo 'Error: ' . mysqli_error($conn);
}
}
}
?>
<img src="./img/MirnesGlamocic.png" class="w-25 mb-3" alt="Web Developer, UI/UX and Web Designer from Bosnia and Herzegovina">
<h1>Feedback</h1>
<?php echo isset($name) ? $name : ''; ?>
<p class="lead text-center">Leave feedback for Mirnes Glamočić</p>
<form method="POST" action="<?php echo htmlspecialchars(
$_SERVER['PHP_SELF']
); ?>" class="mt-4 w-75">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control <?php echo $nameErr ?
'is-invalid': null; ?>" id="name" name="name" placeholder="Enter your name" value="<?php echo $name; ?>">
<div id="validationServerFeedback" class="invalid-feedback">
<?php echo $nameErr; ?>
</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control <?php echo $emailErr ?
'is-invalid': null; ?>" id="email" name="email" placeholder="Enter your email" value="<?php echo $email; ?>">
<div class="invalid-feedback">
<?php echo $emailErr; ?>
</div>
</div>
<div class="mb-3">
<label for="body" class="form-label">Feedback</label>
<textarea class="form-control <?php echo $bodyErr ?
'is-invalid':null; ?>" id="body" name="body" placeholder="Enter your feedback"><?php echo $body; ?></textarea>
<div class="invalid-feedback">
<?php echo $bodyErr; ?>
</div>
</div>
<div class="mb-3">
<input type="submit" name="submit" value="Send" class="btn btn-dark w-100">
</div>
</form>
<?php include 'inc/footer.php'; ?>