-
Notifications
You must be signed in to change notification settings - Fork 1
/
users.php
96 lines (86 loc) · 2.67 KB
/
users.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
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
<html>
<body>
<?php
//defines variables and sets to empty values
$firstName=$lastName=$email=$userID=$userName=$password="";
$fnERR=$lnERR=$emailERR=$userIDERR=$userNameERR=$passwordERR="";
//tests user input on the names of the form controls
function test_user_input($user_input)
{
$user_input=htmlspecialchars($user_input);
$user_input=trim($user_input);
$user_input=stripslashes($user_input);
return $user_input;
}
//When form data is sent with http POST method
if ($_SERVER["REQUEST_METHOD"]=="POST")
{
if(empty($_POST["firstName"])
{
$fnERR="first name required";
}else
{
$firstName=test_user_input($_POST["firstName"]);
if(!preg_match("/^[a-zA-Z ]*$/",$firstName))
{
$fnERR="letter and white space allowed only";
}
}
if(empty($_POST["lastName"])
{
$lnERR="last name required";
}else
{
$lastName=test_user_input($_POST["lastName"]);
if(!preg_match("/^[a-zA-Z ]*$/",$lastName))
{
$lnERR="only letters and white space are allowed";
}
}
if(empty($_POST["email"])
{
$emailERR="email required";
}else
{
$email=test_user_input($_POST["email"]);
if(!filter_var($email,FILTER_VALIDATE_EMAIL))
{
$emailERR="invalid email format";
}
}
if(empty($_POST["userID"]))
{
$userIDERR="user id required";
}else
{
$userID=test_user_input($_POST["userID"]);
}
if(empty($_POST["userName"]))
{
$userNameERR="user name required";
}else
{
$userName=test_user_input($_POST["userName"]);
}
if(empty($_POST["password"]))
{
$passwordERR="password required";
}else
{
$password=test_user_input($_POST["password"]);
}
}
;?>
<fieldset>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ;?>" method="post">
First Name: <input type="text" name="firstName" value="<?php echo $firstName ;?>"><span class="error">*<?php echo $fnERR;?></span><br>
Last Name:<input type="text" name="lastName" value="<?php echo $lastName ;?>"><span class="error">*<?php echo $lnERR ;?></span><br>
E-mail:<input type="text" name="email" value="<?php echo $email;?>"><span class="error">*<?php echo $emailERR ;?></span><br>
User ID:<input type="text" name="userID" value="<?php echo $userID ;?>"><span class="error">*<?php echo $userIDERR ;?></span><br>
User Name:<input type="text" name="userName" value="<?php echo $userName ;?>"><span class="error">*<?php echo $userNameERR ;?></span><br>
Password: <input type="text" name="password" value="<?php echo $password ;?>"><span class="error">*<?php echo $passwordERR ;?></span><br>
<input type="submit" >
</form>
</fieldset>
</body>
</html>