Skip to content

Commit 9dbe47c

Browse files
authored
feat: created contact form for Chelsea (#584)
* feat: created contact form * fix: changed the contact root * chore: fixed grammar and comments * Merge branch 'code-differently:main' into lesson_24 * Merge branch 'code-differently:main' into lesson_24
1 parent 42a8234 commit 9dbe47c

File tree

4 files changed

+1221
-0
lines changed

4 files changed

+1221
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Contact Form</title>
7+
</head>
8+
<body>
9+
<h1>Contact Us</h1>
10+
<form action="/submit" method="POST">
11+
<label for="name">Name:</label>
12+
<input type="text" id="name" name="name" required><br><br>
13+
14+
<label for="email">Email:</label>
15+
<input type="email" id="email" name="email" required><br><br>
16+
17+
<label for="message">Message:</label><br>
18+
<textarea id="message" name="message" rows="4" cols="50" required></textarea><br><br>
19+
20+
<button type="submit">Submit</button>
21+
</form>
22+
</body>
23+
</html>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const express = require("express");
2+
const app = express();
3+
const port = 5000;
4+
const cors = require("cors");
5+
const path = require("path");
6+
7+
app.use(express.urlencoded({ extended: true }));
8+
app.use(express.json());
9+
app.use(cors()); // Enable CORS globally
10+
11+
// Serve static files from the 'express_app' directory
12+
app.use(express.static(path.join(__dirname, 'express_app')));
13+
14+
// Serve the contact form at the root
15+
app.get("/", (req, res) => {
16+
res.sendFile(path.join(__dirname, 'contact.html'));
17+
});
18+
19+
// Handle form submission
20+
app.post("/submit", (req, res) => {
21+
const { name, email, message } = req.body;
22+
23+
// Log the form data to the console
24+
console.log("Received submission:");
25+
console.log(`Name: ${name}`);
26+
console.log(`Email: ${email}`);
27+
console.log(`Message: ${message}`);
28+
29+
// Send a response back to the user
30+
res.send(`
31+
<h1>Thank you for your submission, ${name}!</h1>
32+
<p>We have received your message and will get back to you at ${email} soon.</p>
33+
<a href="/">Go back to the contact form</a>
34+
`);
35+
});
36+
37+
// Start the server
38+
app.listen(port, () => {
39+
console.log(`Listening at http://localhost:${port}`);
40+
});

0 commit comments

Comments
 (0)