-
Notifications
You must be signed in to change notification settings - Fork 0
/
formValidation.php
53 lines (49 loc) · 1.85 KB
/
formValidation.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
<!DOCTYPE html>
<html>
<body>
<h1>My First PHP page</h1>
<?php
$name = $email = $gender = $comment = $website = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
$name = testInput($_POST["name"]);
$email = testInput($_POST["email"]);
$website = testInput($_POST["website"]);
$comment = testInput($_POST["comment"]);
$gender = testInput($_POST["gender"]);
}
function testInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h1>PHP Form Validation Example</h1>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
Name : <input type="text" name="name" />
<br><br>
E-Mail : <input type="email" name="email">
<br><br>
Website : <input type="text" name="website">
<br><br>
Comment : <textarea name="comment" rows="5" cols="40" style="display:block;"></textarea>
<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="other" />Other
<br><br>
<input type="submit" value="Submit">
</form>
<?php
if($name !="" || $email !="" || $website != "" || $comment != "" || $gender !=""){
echo "<h2>Your Input : </h2>";
echo "<p>Name : " . $name . "</p>";
echo "<p>E-Mail : " . $email . "</p>";
echo "<p>Website : " . $website . "</p>";
echo "<p>Comment : " . $comment . "</p>";
echo "<p>Gender : " . $gender . "</p>";
}
?>
</body>
</html>