-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedback_backhand.php
83 lines (74 loc) · 1.94 KB
/
feedback_backhand.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
<?php
// define variables and set to empty values
$nameErr = $emailErr = $subjectErr = $rateErr= $commentErr = "";
$name = $email = $subject = $comment=$rate = "";
$response="";
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$response="";
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
$name="";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
$email = "";
}
}
if (empty($_POST["subject"])) {
$subjectErr = "Subject is required";
} else {
$subject = test_input($_POST["subject"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$subject)) {
$subjectErr = "Only letters and white space allowed";
$subject= "";
}
}
if (empty($_POST["comment"])) {
$commentErr = "Comment is required";
} else {
$comment = test_input($_POST["comment"]);
}
if (empty($_POST["rate"])) {
$rateErr = "rating is required";
} else {
$rate = test_input($_POST["rate"]);
}
if($name!=""&&$email!=""&&$subject!=""&&$comment!=""&&$rate!="")
{
$myfile=fopen("example.txt","a");
$feedback=$name.' '.$email.' '.$subject.' '.$comment.' '.$rate."\r\n";
fwrite($myfile,$feedback);
fclose($myfile);
/*
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $subject;
echo "<br>";
echo $comment;
echo "<br>";
*/
$name = $email = $subject = $comment = $rate="";
}
}