-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_test2.txt
66 lines (60 loc) · 1.59 KB
/
form_test2.txt
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
<html>
<head>
</head>
<body>
<?php
$name = $email = $gender = $comment = $website = $maritalstatus = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$website = test_input($_POST["website"]);
$comment = test_input($_POST["comment"]);
$gender = test_input($_POST["gender"]);
$maritalstatus = test_input($_POST["maritalstatus"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation</h2><br>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="7" cols="80"></textarea>
<br><br><br>
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="homo">Homo
<br><br><br>
Marital-Satus:
<input type="radio" name="maritalstatus" value="married">Married
<input type="radio" name="maritalstatus" value="divorced">Divorced
<input type="radio" name="maritalstatus" value="single'>Single
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>My Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
echo "<br>";
echo $maritalstatus;
echo "<br>";
?>
</body>
</html>