forked from maiz-an/The-Gallery-Cafe-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact_form.php
More file actions
121 lines (104 loc) · 4.15 KB
/
Copy pathcontact_form.php
File metadata and controls
121 lines (104 loc) · 4.15 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
<?php
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "product_website";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Handle form submission via AJAX
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['ajax'])) {
$name = $conn->real_escape_string($_POST['name']);
$email = $conn->real_escape_string($_POST['email']);
$message = $conn->real_escape_string($_POST['message']);
$sql = "INSERT INTO contact_submissions (name, email, message) VALUES ('$name', '$email', '$message')";
if ($conn->query($sql) === TRUE) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'error' => $conn->error]);
}
$conn->close();
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Us - The Gallery Café</title>
<link rel="stylesheet" href="style/contact_form_style.css">
<link rel="stylesheet" href="style/loader.css">
<script src="js/loader.js" defer></script>
<script src="js/back_button.js" defer></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
document.querySelector("form").addEventListener("submit", function(e) {
e.preventDefault(); // Prevent the form from submitting the traditional way
const formData = new FormData(this);
formData.append('ajax', true);
fetch('contact_form.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Your message has been sent successfully!');
window.location.href = window.location.pathname; // Reload the page to clear the form
} else {
alert('There was an error: ' + data.error);
}
})
.catch(error => {
console.error('Error:', error);
});
});
});
function goBack() {
window.history.back();
}
</script>
</head>
<body>
<div id="loader">
<img src="images/logo.png" alt="The Gallery Café Logo">
<p>Loading, please wait...</p>
</div>
<main>
<button onclick="goBack()" class="btn nav-btn back-btn">Back</button>
<section id="contact-info">
<h2>Contact Us</h2>
<section class="center-section">
<a href="tel:+94753357777" class="pbutton">
<span class="shine"></span>
</a>
<a href="mailto:mohamedmaizanmunas@outlook.com" class="ebutton contact-link"></a>
<a href="https://www.instagram.com/mr.de11_?igsh=M2NrOWcwcjNicGp0&utm_source=qr" target="_blank" class="ibutton contact-link"></a>
<a href="https://www.facebook.com/profile.php?id=61553304986903&mibextid=LQQJ4d" target="_blank" class="fbutton contact-link"></a>
</section>
</section>
<section>
<form method="post">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
</div>
<input type="submit" value="Send Message" class="btn">
</form>
</section>
</main>
</body>
</html>