-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.php
56 lines (51 loc) · 1.9 KB
/
create.php
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
<?php
include 'functions.php';
$pdo = pdo_connect_mysql();
// Output message variable
$msg = '';
// Check if POST data exists (the user submitted the form)
if (isset($_POST['title'], $_POST['email'], $_POST['msg'])) {
// Validation checks... make sure the POST data is not empty
if (empty($_POST['title']) || empty($_POST['email']) || empty($_POST['msg'])) {
$msg = 'Please complete the form!';
} else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$msg = 'Please provide a valid email address!';
} else {
// Insert new record into the tickets table
$stmt = $pdo->prepare('INSERT INTO tickets (title, email, msg) VALUES (?, ?, ?)');
$stmt->execute([ $_POST['title'], $_POST['email'], $_POST['msg'] ]);
// Redirect to the view ticket page. The user will see their created ticket on this page.
header('Location: view.php?id=' . $pdo->lastInsertId());
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Ticket</title>
<!-- Link to your CSS stylesheet -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?=template_header('Create Ticket')?>
<div class="content create">
<h2>Create Ticket</h2>
<form action="create.php" method="post">
<label for="title">Title</label>
<input type="text" name="title" placeholder="Title" id="title" required>
<label for="email">Email</label>
<input type="email" name="email" placeholder="johndoe@example.com" id="email" required>
<label for="msg">Message</label>
<textarea name="msg" placeholder="Enter your message here..." id="msg" required></textarea>
<input type="submit" value="Create">
</form>
<?php if ($msg): ?>
<p><?=$msg?></p>
<?php endif; ?>
</div>
<?=template_footer()?>
</body>
</html>