-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformvalidattionProject.php
More file actions
122 lines (112 loc) · 3.11 KB
/
formvalidattionProject.php
File metadata and controls
122 lines (112 loc) · 3.11 KB
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
<?php
$NameError = "";
$EmailError = "";
$GenderError = "";
$WebsiteError = "";
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
{
$NameError = "Name is Required";
}
else
{
$Name = Test_User_Input($_POST['name']);
if (!preg_match("/^[A-Za-z\. ]*$/", $Name)) {
$NameError = "Only Letters and white spaces are allowed.";
}
}
if(empty($_POST['email']))
{
$EmailError = "Email is Required";
}
else
{
$Email = Test_User_Input($_POST['email']);
if (!preg_match("/[A-Za-z0-9._-]{3,}@[A-Za-z0-9._-]{3,}[.]{1}[A-Za-z0-9._-]{2,}/", $Email)) {
$EmailError = "Invalid Email Format";
}
}
if(empty($_POST['gender']))
{
$GenderError = "Gender is Required";
}
else
{
$Gender = Test_User_Input($_POST['gender']);
}
if(empty($_POST['website']))
{
$WebsiteError = "Website is Required";
}
else
{
$Website = Test_User_Input($_POST['website']);
if (!preg_match("/(https:|ftp:)\/\/+[A-Za-z0-9.\-_\/?\$=&\#\~`!]+\.[A-Za-z0-9.\-_\/?\$=&\#\~`!]*/", $Website)) {
$WebsiteError = "Invalid Website Address Format";
}
}
}
if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['gender']) && !empty($_POST['website'])) {
if ((preg_match("/^[A-Za-z\. ]*$/", $Name)==true) && (preg_match("/[A-Za-z0-9._-]{3,}@[A-Za-z0-9._-]{3,}[.]{1}[A-Za-z0-9._-]{2,}/", $Email)==true) && (preg_match("/(https:|ftp:)\/\/+[A-Za-z0-9.\-_\/?\$=&\#\~`!]+\.[A-Za-z0-9.\-_\/?\$=&\#\~`!]*/", $Website)==true)) {
echo "<h2> Your Submit Information: </h2><br>";
echo "Name : ".ucwords($_POST['name'])."<br>";
echo "Email : {$_POST['email']}<br>";
echo "Gender : {$_POST['gender']}<br>";
echo "Website : {$_POST['website']}<br>";
echo "Comment : {$_POST['comment']}<br>";
}
else
{
echo '<span class="Error">Please complete and correct your Form Again!</span>';
}
}
function Test_User_Input($Data)
{
return $Data;
}
?>
<html>
<head>
<title>Form Validation</title>
</head>
<style type="text/css">
input[type="text"],input[type="email"],textarea{
border: 1px solid dashed;
background-color: rgb(221,216,212);
width: 600px;
padding: 0.5em;
font-size: 1.0em;
}
.Error{
color: red;
}
</style>
<body>
<?php ?>
<h2>Form Validation with PHP.</h2>
<form action="formvalidattionProject.php" method="POST">
<legend>* Please Fill Out the Following Fields.</legend>
<fieldset>
Name : <br>
<input type="text" name="name">
<span class="Error">* <?php echo $NameError;?> </span><br>
E-mail : <br>
<input type="text" name="email">
<span class="Error">* <?php echo $EmailError;?> </span><br>
Gender : <br>
<input type="radio" name="gender" value="Male"> Male</input>
<input type="radio" name="gender" value="Female"> Female </input>
<span class="Error">* <?php echo $GenderError;?> </span><br>
Website : <br>
<input type="text" name="website">
<span class="Error">* <?php echo $WebsiteError;?> </span><br>
Comment : <br>
<textarea name="comment" rows="5" cols="25"></textarea>
<br>
<br>
<input type="submit" name="submit" value="Submit">
</fieldset>
</form>
</body>
</html>