-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.php
159 lines (135 loc) · 5.19 KB
/
form.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="Himanshu">
<meta name="author" content="Kyle">
<title>Submit Hours</title>
<style>
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical
}
input[type=submit] {
background-color: #656464;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.container {
border-radius: 5px;
padding: 20px;
background-color: #f2f2f2;
}
body {
background-color: #6600cc;
}
input {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Please put in the hours you are available or delete hours you have already posted</h2>
<form action="form.php" method="post">
Email:
<br>
<input type="email" name="email" required>
<br>
Name:
<br>
<input type="text" name="full_name" required>
What Day You Can Tutor:
<br>
<select class="form-control" id="day" name="day" required>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
</select>
Start Time
<br>
<input type="time" name="start_time" required>
<br>
End Time
<br>
<input type="time" name="end_time" required>
<br>
<input type="submit" name="btnSubmit" value="Submit">
<input type="submit" name="btnDelete" value="Delete">
</form>
<br>
<a href="index.html">Go back to homepage</a>
</div>
<?php
// Report all error information on the webpage
error_reporting(E_ALL);
ini_set('display_errors', 1);
//check if variables are not empty and what button is pressed
if (!empty($_POST))
{
//if submit button pressed write input to text file seperated by #,,#
if (isset($_POST['btnSubmit']))
{
$myfile = fopen("tutor_info.txt", "a");
fwrite($myfile, $_POST["email"] . "#,,#");
fwrite($myfile, $_POST["full_name"] . "#,,#");
fwrite($myfile, $_POST["day"] . "#,,#");
fwrite($myfile, $_POST["start_time"] . "#,,#");
fwrite($myfile, $_POST["end_time"] . "\n");
fclose($myfile);
echo '<script type="text/javascript">',
'alert("You have successfully submitted your hours");',
'</script>';
}
//if delete button pressed
if (isset($_POST['btnDelete']))
{
$found = false; //for checking if line to delete exists in file
$del_line = $_POST["email"] . "#,,#" . $_POST["full_name"] . "#,,#" . $_POST["day"] . "#,,#"
. $_POST["start_time"] . "#,,#" . $_POST["end_time"] . "\n";
$lines = file("tutor_info.txt"); //array with lines from file
$output = '';
//store line in $output if it is not equal to $del_line
foreach ($lines as $line)
{
if ($line!==$del_line)
{
$output .= $line;
}
else
{
$found = true;
}
}
//delete successful
if($found)
{
// replace contents of the file with the output
file_put_contents("tutor_info.txt", $output);
echo '<script type="text/javascript">',
'alert("You have successfully deleted your hours");',
'</script>';
}
//delete values not found in text file
else
{
echo '<script type="text/javascript">',
'alert("Not Found, Please check the Values");',
'</script>';
}
}
}
?>
</body>
</html>