-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.php
More file actions
200 lines (164 loc) · 4.29 KB
/
form.php
File metadata and controls
200 lines (164 loc) · 4.29 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
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
<?php
if(isset($_POST['submit'])){
if($_POST['nam2']==""){
$error_msg['nam2']= " *Name is required";
}
$nam2=$_POST['nam2'];
if(!preg_match("/^[a-zA-Z ]*$/",$nam2)){
$error_msg['nam2']= " *Only letters allowed";
}
$email=$_POST['email'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_msg['email'] = " *Invalid email format";
}
$phone=$_POST['phone'];
if (empty($phone)) {
$error_msg['phone'] = " *Number is required";
}
if (empty($_POST["website"])) {
$error_msg['Website']= " *URL is required"; } else {
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$Website)) {
$error_msg['Website']= " *Invalid URL";
}
}
if($_POST['comment']==""){
$error_msg['comment']= " *comment is required";
}
if (empty($_POST["gender"])) {
$error_msg['gender'] = "Gender is required";}
if (empty($_POST["checkbox"])) {
$error_msg['checkbox'] = "*Checkbox is required";}
}
?>
<html>
<head>
<style>
.error{
color:#060606 ;
padding-top:0px;
float:right;
width:100%;
}
</style>
</head>
<body >
<table >
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<tr>
<td><h1>Name: </h1></td>
<td><input type ="text" name="nam2"></td>
<td>
<?php
if (isset($error_msg['nam2'])){
echo "<div class='error'>".$error_msg['nam2']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td><h1>Email:</h1></td>
<td><input type ="text" name="email"></td>
<td>
<?php
if (isset($error_msg['email'])){
echo "<div class='error'>".$error_msg['email']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td><h1>Phone:</h1></td>
<td><input type ="text" name="phone"></td>
<td>
<?php
if (isset($error_msg['phone'])){
echo "<div class='error'>".$error_msg['phone']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td><h1>Website:</h1></td>
<td><input type ="text" name="website"></td>
<td>
<?php
if (isset($error_msg['Website'])){
echo "<div class='error'>".$error_msg['Website']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td><h1>Comment:</h1></td>
<td><textarea name="comment" id="comment" cols="18" rows="5"></textarea></td>
<td>
<?php
if (isset($error_msg['comment'])){
echo "<div class='error'>".$error_msg['comment']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td><h1>Gender:</h1></td>
<td><input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="other") echo "checked";?>
value="other">Other <br></td>
<td>
<?php
if (isset($error_msg['gender'])){
echo "<div class='error'>".$error_msg['gender']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td><h5>Agree to Teams of Service:</h5></td>
<td><input type="checkbox" name="checkbox" id="check"></td>
<td>
<?php
if (isset($error_msg['checkbox'])){
echo "<div class='error'>".$error_msg['checkbox']."</div>";
}
?><br>
</td>
</tr>
<tr>
<td>>>>>>>>>>>>>>>>>>>>>></td>
<td><input type="submit" name="submit" value="Submit"></td>
<td><<<<<<<<<<<<<<<<<<<<<</td>
</tr>
</form>
</table>
<?php
echo "Name:";
echo $_POST["nam2"] ;
echo "<br>";
echo "Email:";
echo $_POST["email"] ;
echo "<br>";
echo "Phone:";
echo $_POST["phone"] ;
echo "<br>";
echo "Website:";
echo $_POST["website"] ;
echo "<br>";
echo "Comment:";
echo $_POST["comment"] ;
echo "<br>";
echo "Gender:";
echo $_POST["gender"] ;
echo "<br>";
echo "checkbox:";
echo $_POST["checkbox"] ;
echo "<br>";
?>
</body>
</html>