forked from snehshrivastava/Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1_studentsform.php
More file actions
78 lines (75 loc) · 3.11 KB
/
project1_studentsform.php
File metadata and controls
78 lines (75 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
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$nameErr=$emailErr=$anoErr=$genderErr="";
$name=$email=$ano=$gender="";
if($_SERVER["REQUEST_METHOD"]=="POST") {
if(empty($_POST["name"])) {
$nameErr="Name is Required";
}
else {
$name=test_input($_POST["name"]);
if(!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr="Only letters and blank spaces are allowed";
}
}
if(empty($_POST["email"])) {
$emailErr="Email is required";
}
else {
$email=test_input($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr="INvalid Email format";
}
}
if(empty($_POST["ano"])) {
$anoErr="Admission No is Required";
}
else
{
$ano=test_input($_POST["ano"]);
if(!preg_match("/^[a-zA-Z0-9]*$/",$ano)){
$anoErr="Invalid admission no.";
}
}
if(empty($_POST["gender"])) {
$genderErr="Gender is Required";
}
else {
$gender=test_input($_POST["gender"]);
}
}
function test_input($data) {
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
?>
<h2>sign up for students</h2>
<p><span class = "error" >* required fields</span></p>
<form method = "post" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
NAME: <input type="text" name="name" value = "<?php echo $name; ?>">
<span class="error" >* <?php echo $nameErr; ?></span>
<br><br>
EMAIL: <input type="text" name="email" value = "<?php echo $email; ?>">
<span class= "error">* <?php $emailErr; ?></span>
<br><br>
Admission No.: <input type="text" name ="ano" value = "<?php echo $ano; ?>">
<span class = "error" >* <?php echo $anoErr; ?></span>
<br><br>
Gender:
<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
<span class="error" >* <?php echo $genderErr; ?></span>
<br><br>
<input type = "submit" name= " submit " value = "Submit">
</form>
</body>
</html>