-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject4.php
279 lines (247 loc) · 8.65 KB
/
Project4.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="favicon-32x32.png" href="favicon-32x32.png" sizes="32x32" />
<title>Empty form</title>
</head>
<h1>
<!-- Google Images Credit-->
<img src="http://i30.photobucket.com/albums/c331/edwardtu/GreenBayPackers_zps1772cf1b.png" alt="Packers"
style="width: 100%;height:100px;">
</h1>
<body style="background-color:lightyellow">
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #006600;
}
li {
float: left;
}
li a {
display: block;
color: lightyellow;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: grey;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="index.htm">Home</a></li>
<li><a href="Schedule.html">Green Bay Schedule</a></li>
<li><a href="Game_outcomes.html">Game Outcomes</a></li>
<li><a href="Project2.html">Empty Form</a></li>
<li><a href="About.html">About</a></li>
<li><a href="Resume.html">Resume</a></li>
<li><a href="Project3.html">Project3</a></li>
</ul>
</body>
<style>
input[type=text], select {
width: 100%;
font: fantasy;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #000000;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
font: fantasy;
background-color: white;
color: black;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: lightyellow;
}
div {
border-radius: 5px;
font: fantasy;
background-color: #006600;
padding: 20px;
}
</style>
<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
</head>
<body>
<?php
/* Email Form
* This is a simple email form that is used to demonstrate PHP validation. This
* particular file also demonstrates using PHP to display HTML elements
*/
$labels = array("to" => "TO:", "from" => "FROM:", "CC" => "CC:",
"subject" => "SUBJECT:", "body" => "BODY:", "Type_email" => "TYPE OF EMAIL:");
?>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $subErr = $msgErr = $typeErr = $invalidErr = $responseErr = "";
$name = $email = $type = $body = $subject= $response = $success_message = $headers = $Dropdown = "";
$dropdown_vals = array('Comment', 'Urgent', 'Question');
$selected_key = $_POST['Dropwdown'];
$selected_val = $dropdown_vals[$_POST['Dropdown']];
$name_value = isset($_POST['name'])?$_POST['name']:'[email protected]';
$email_value = isset($_POST['from'])?$_POST['from']:'';
$subject_value = isset($_POST['subject'])?$_POST['subject']:'';
$body_value = isset($_POST['body'])?$_POST['body']:'';
$cc_value = isset($_POST['CC'])?$_POST['CC']:'';
//$Dropdown = isset($_POST['Dropdown'])?$_POST['Dropdown']:'';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//if name is empty or contains special chars / numbers echo Err
if (empty($_POST["name"])) {
$nameErr = "Name is required";
}else if(preg_match('/[\'^£$%&*()}@#~?><>,|=_+¬-]/', $name)) {
} else {
$name = test_input($_POST["name"]);
if(preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $name) or preg_match('/[0-9]/', $name)) {
$nameErr = "Invalid characters in name";
} else {
$nameErr = "";
}
}
//is SUB is empty echo errr
if (empty($_POST["subject"])) {
$subErr = "Subject is required";
} else {
$subErr = "";
$subject = test_input($_POST["subject"]);
}
//if body is empty echo err
if (empty($_POST["body"])) {
$msgErr = "Text is required";
} else {
$msgErr = "";
$body = test_input($_POST["body"]);
}
if (empty($_POST["from"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["from"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
} else {
$emailErr = "";
}
} if(empty($msgErr) && empty($subErr) && empty($emailErr)) {
//echo "Hello";
$headers = "From: $email_value" . "\r\n" . "CC: $email_value" . "\r\n" . "CC: $cc_value";
$body_value = $selected_val . ":\r\n\n" . $body_value;
mail($name_value, $subject_value, $body_value, $headers);
//mail($cc_value, $subject_value, $body_value, $email_value);
$body_value = $cc_value = $subject_value = $email_value = "";
$success_message = "Email Sent";
if(isset($success_message)) {
echo $success_message;
}
}
}
//tests input from strings
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<html>
<head>
<title>Form</title>
<style type ="text/css">
<!--
form {margin: 1.5em 0 0 0; padding: 0;}
.field {padding-top: .5em; font-family: fantasy; text-align:left;}
.error {color: #FF0000;}
label {font-weight: bold; float: left;
margin-right: 1em; text-align: left;}
#submit {margin-left: 35%; padding-top: 1em;}
-->
</style>
</head>
<body>
<h3 style = "font-family: fantasy;">Please fill out the form and click submit to send an email.</h3>
<p><span class="error"> * = required field.</span></p>
<form method = "POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<?php
/* Loop that displays the form fields */
foreach ($labels as $field => $label) {
/* echo the label */
echo "<div class='field';text-align: left;>
<label for='$field'>$label</label>\n";
/* echo the appropriate field */
if ($field === "to" or $field === "from" or $field === "subject" or $field === "BODY" or "CC" or "Type_email")
{
//creates form and validates
if($field === "to") {
echo "<input type='text' name='$field' id='$field' value='$name_value'
size='90' maxlength='80' />\n";
echo "<span class='error'>*
$emailErr";
}
if($field === "from") {
echo "<input type='text' name='$field' id='$field' value='$email_value'
size='90' maxlength='80' />\n";
echo "<span class='error'>*
$emailErr";
}
if($field === "CC") {
echo "<input type='text' name='$field' id='$field' value='$cc_value'
size='90' maxlength='80' />\n";
echo "<span class='error'>*
$emailErr";
}
if($field === "subject") {
echo "<input type='text' name='$field' id='$field' value='$subject_value'
size='90' maxlength='80' />\n";
echo "<span class='error'>*
$subErr";
}
if($field === "body") {
echo "<input type='text' name='$field' id='$field' value='$body_value'
size='90' maxlength='80' />\n";
echo "<span class='error'>*
$msgErr";
}
if($field === "Type_email") {
echo "<select name = 'Dropdown'>
<option value='0'>--Select an Option--</option>
<option value='1'>Comment</option>
<option value='2'>Urgent</option>
<option value='3'>Question</option>
</select>\n";
}
/* echo the end of the field div */
echo "</div>\n";
}
}
/* Display the submit button */
echo "<div id='submit;text-align:center;'>\n
<input type='submit' name='submit' value='Submit'>\n
</div>\n</form>\n</body>\n</html>";
?>
<!-- Wait, where are the ending <form>, <body>, and <html> tags? Oh, they’re
Imbedded in the PHP code just above. That’s Ok, then. -->
</body>
</html>
<br>
<br>
</body>
</body>
</html>