-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
72 lines (72 loc) · 2.92 KB
/
Copy pathsignup.php
File metadata and controls
72 lines (72 loc) · 2.92 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
<?php
require 'includes/header.php';
// CONNECT TO DATABASE
include 'includes/library.php';
$pdo = connectdb();
if ($_SESSION == null) {$_SESSION['userid'] = 0;}
$userid = $_SESSION['userid'];
// CREATE ARRAY FOR ERRORS
$errors = array();
// GET AND SANTIZE EACH INPUT
$title = trim(filter_var($_POST['title'] ?? null, FILTER_SANITIZE_STRING));
$description = trim(filter_var($_POST['description'] ?? null, FILTER_SANITIZE_STRING));
$privacy = trim(filter_var($_POST['privacy'] ?? null, FILTER_SANITIZE_STRING));
// POST SUBMISSION
if (isset($_POST['save'])) {
// CHECK TITLE FIELD
if (!isset($title) || strlen($title) === 0) { $errors['title'] = true; }
// CHECK DESCRIPTION FIELD
if (!isset($description) || strlen($description) === 0) { $errors['description'] = true; }
// CHECK PRIVACY FIELD
if (empty($privacy)) { $errors['privacy'] = true; }
// ERROR VERIFICATION
if(count($errors)=== 0) {
$query = "INSERT into signin_info values (NULL,?,?,$userid,?,NULL,NULL,Now())";
$stmt = $pdo->prepare($query)->execute([$title,$description,$privacy]);
$_SESSION['sheetid']=$pdo->lastInsertId();
// REDIRECT
header("Location: timeslot.php");
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php $page_title = "Sign Up Sheet"; ?>
<script src="https://kit.fontawesome.com/6786f5cbb4.js" crossorigin="anonymous"></script>
<?php include "includes/metadata.php" ?>
</head>
<body>
<section class="signup">
<form id="signupform" action="<?=htmlentities($_SERVER['PHP_SELF']);?>" method="post" novalidate>
<h2>Create Your Sign Up Sheet</h2>
<h3>*****Step One*****</h3>
<div class="input">
<label for="title">Sheet Title</label>
<input id="title" name="title" type="text" placeholder="COIS 3420 Project" value="<?=$title?>"/>
<span class="error <?=!isset($errors['title']) ? 'hidden' : "";?>">Please enter a sheet title</span>
</div>
<div class="input">
<label for="description">Description</label>
<textarea name="description" id="description" cols="50" rows="5" value="<?=$description?>"></textarea>
<span class="error <?=!isset($errors['description']) ? 'hidden' : "";?>">Please enter your description</span>
</div>
<fieldset>
<legend>Privacy</legend>
<div>
<input id="public" name="privacy" type="radio" value="Y" <?=$privacy == "Y" ? 'checked' : ''?> />
<label for="public">Public</label>
</div>
<div>
<input id="private" name="privacy" type="radio" value="N" <?=$privacy == "N" ? 'checked' : ''?> />
<label for="private">Private</label>
</div>
</fieldset>
<span class="error <?=!isset($errors['privacy']) ? 'hidden' : "";?>">Please choose one</span>
<button id="save" name='save'>Save </button>
</form>
</section>
<?php include "includes/footer.php" ?>
</body>
</html>