-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask4.php
More file actions
216 lines (167 loc) · 7.06 KB
/
task4.php
File metadata and controls
216 lines (167 loc) · 7.06 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
function Clean($input){
$input = trim($input);
$input = strip_tags($input);
$input = stripslashes($input);
return $input;
// return stripslashes(strip_tags(trim($input)));
}
# Errors Array ...
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$name = Clean($_POST['name']);
$email = Clean($_POST['email']);
$password = $_POST['password'];
$adress = Clean($_POST['adress']);
$gender = $_POST['gender'];
$linkedin = $_POST['linkedin'];
# Validate Name .....
if(empty($name)){
$errors['Name'] = "Required Field ";
}elseif(is_int($name)){
$errors['Name'] = "<p class='Ralert'>NotValid Name</p>";
}else{
$errors['Name'] = "<p class='Gsuss'>Valid Name</p>";
}
/* else{
//$alpha = ['a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z'];
//$mName = explode('',$name);
} */
# Validate Email ...
if(empty($email)){
$errors['Email'] = "<p class='Ralert'>Email Required</p>";
}elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)){
$errors['Email'] = "<p class='Ralert'>Invalid Email Format</p>";
}elseif(filter_var($email,FILTER_VALIDATE_EMAIL)){
$errors['Email'] = "<p class='Gsuss'>Valid Email</p>";
}
# Validate Password ....
if(empty($password)){
$errors['Password'] = "Required Field";
}elseif(strlen($password) < 6){
$errors['Password'] = "Password Length Must Be >= 6 Chars";
}
# Validate Adress ....
if(empty($adress)){
$errors['Adress'] = "Required Field";
}elseif(strlen($adress) < 10){
$errors['Adress'] = "Adress Length Must Be >= 10 Chars";
}
# Validate Gender ....
if(empty($gender)){
$errors['Gender'] = "<p class='Ralert'>Not Valide Gender Choose</p>";
}elseif($gender = 'male' or $gender = 'female'){
echo '<p class="Gsuss">Valide Gender Choose</p>';
}
# Validate linkedin ...
$inUrl = explode('.com/',$linkedin);
if(empty($linkedin)){
$errors['Linkedin'] = "Required Field";
}elseif(!filter_var($linkedin,FILTER_VALIDATE_URL)){
$errors['Linkedin'] = "Invalid Format";
}elseif ($inUrl[0] == "http://www.linkedin" or $inUrl[0] == "http://linkedin" or $inUrl[0] == "https://www.linkedin" or $inUrl[0] == "https://linkedin") {
$errors['Linkedin'] = "<p class='Gsuss'>valid linked in</p>";
}else{
$errors['Linkedin'] = "<p class='Ralert'>NOT valid linked in</p>";
}
# Check Errors ......
if(count($errors) > 0 ){
/* foreach ($errors as $key => $value) {
# code...
echo '* '.$key.' : '.$value.'<br>';
} */
echo '<p class="Ralert">RegisterationFailed</p>';
}else{
echo '<p class="Gsuss">Registered Sucssesfully</p>';
}
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
// CODE .....
if (!empty($_FILES['pdf']['name'])) {
$imgName = $_FILES['pdf']['name'];
$imgTemName = $_FILES['pdf']['tmp_name'];
$imgType = $_FILES['pdf']['type'];
$imgSize = $_FILES['pdf']['size'];
# Allowed Extensions
$allowedExtensions = ['pdf'];
$imgArray = explode('/', $imgType);
# pdf Extension ......
$pdfExtension = end($imgArray);
if (in_array($pdfExtension, $allowedExtensions)) {
# pdf New Name ......
$FinalName = time() . rand() . '.' . $pdfExtension;
$disPath = 'uploads/' . $FinalName;
if (move_uploaded_file($imgTemName, $disPath)) {
echo 'pdf Uploaded Succ ';
} else {
echo 'Error try Again';
}
} else {
echo 'InValid Extension .... ';
}
} else {
echo '<p class="Gsuss">* pdf Required</p>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Register</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.Ralert{
color: red;
}
.Gsuss{
color: green;
}
</style>
</head>
<body>
<div class="container">
<h3>Register</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputName">Name</label>
<input type="text" class="form-control" id="exampleInputName" aria-describedby="" name="name" placeholder="Enter Name">
<?php if(isset($errors['Name'])) {echo $errors['Name'];} ?>
</div>
<div class="form-group">
<label for="exampleInputEmail">Email address</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="email" placeholder="Enter email">
<?php if(isset($errors['Email'])) {echo $errors['Email'];} ?>
</div>
<div class="form-group">
<label for="exampleInputPassword">New Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="password" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleAdressName">Adress</label>
<input type="text" class="form-control" id="exampleAdressName" aria-describedby="" name="adress" placeholder="Enter Adress">
</div>
<div class="form-group">
<label for="exampleGenderName">Gender</label>
<select class="form-control" id="exampleGenderName" aria-describedby="" name="gender">
<option value="">--- Choose Gender ---</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="form-group">
<label for="exampleLinkedURL">LinkedIn URL</label>
<input type="text" class="form-control" id="exampleLinkedURL" aria-describedby="" name="linkedin" placeholder="Enter LinkedIn URL">
</div>
<div class="form-group">
<label for="exampleInputName">Upload Your CV</label>
<input type="file" name="pdf">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>