Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 7cb14280 authored by 65160394's avatar 65160394
Browse files

Project Round 3

parent 516bf2b7
No related branches found
No related tags found
No related merge requests found
......@@ -83,19 +83,22 @@ exports.Logout = (req, res) => {
//CRUD
// ฟังก์ชั่นสำหรับแสดงฟอร์มสร้างทัวร์
exports.getCreateTour = (req, res) => {
res.render('createtour', { message: null }); // แสดงฟอร์มสร้างทัวร์
res.render('createtour', { message: null }); // ไม่ต้องดึงข้อมูลทัวร์ใด ๆ
};
exports.createTour = async (req, res) => {
const { name, description, price, duration } = req.body;
try {
// สร้างทัวร์ใหม่ในฐานข้อมูล
await Tour.createTour({ name, description, price, duration });
res.redirect('/'); // ไปยังหน้าหลักหลังจากสร้างทัวร์เสร็จ
if (!name || !description || !price || !duration) {
return res.render('createtour', { message: 'All fields are required!' });
}
await Tour.createTour({ name, description, price, duration }); // เพิ่มข้อมูลทัวร์
res.redirect('/'); // หลังจากสร้างเสร็จให้กลับไปที่หน้าแรก
} catch (error) {
console.error(error);
res.render('createtour', { message: error.message }); // แสดงข้อความข้อผิดพลาด
console.error('Error creating tour:', error);
res.render('createtour', { message: 'Error creating tour' });
}
};
// ฟังก์ชั่นสำหรับสร้างทัวร์
......
......@@ -15,19 +15,19 @@
<form action="/tour/create" method="POST">
<div>
<label for="tourName">Tour Name:</label>
<input type="text" id="tourName" name="tourName" required>
<input type="text" id="tourName" name="name" required>
</div>
<div>
<label for="tourDescription">Description:</label>
<textarea id="tourDescription" name="tourDescription" required></textarea>
<textarea id="tourDescription" name="description" required></textarea>
</div>
<div>
<label for="tourPrice">Price:</label>
<input type="number" id="tourPrice" name="tourPrice" required>
<input type="number" id="tourPrice" name="price" required>
</div>
<div>
<label for="tourDate">Date:</label>
<input type="date" id="tourDate" name="tourDate" required>
<label for="tourDuration">Duration (days):</label>
<input type="number" id="tourDuration" name="duration" required>
</div>
<button type="submit">Create Tour</button>
</form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment