-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
148 lines (126 loc) · 3.69 KB
/
index.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
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Sign up Page</title>
<style>
.error {color: #FF0000;}
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
<body>
<?php
include "subscription.php";
// define variables
$fNameErr = $lNameErr = $mNumberErr = $emailErr = "";
$firstName = $lastName = $mobileNumber = $email = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$firstName = $_POST["firstName"];
if (empty($firstName)){
$fNameErr = "First Name is required";
} else {
$firstName = input($_POST["firstName"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$firstName)) {
$fNameErr = "Only letters and white space allowed.";
}
}}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$lastName = $_POST["lastName"];
if (empty($lastName)){
$lNameErr = "Last Name is required";
} else {
$lastName = input($_POST["lastName"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$lastName)) {
$lNameErr = "Only letters and white space allowed";
}
}}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$mobileNumber = $_POST["mobileNumber"];
if (empty($mobileNumber)){
$mNumberErr = "Mobile Number is required";
} else {
$mobileNumber = input($_POST["mobileNumber"]);
// check if mobile number is digits
if (!preg_match("/^\d{10}$/",$mobileNumber)) {
$mNumberErr = "Please enter 10 digit mobile number";
}
}}
if ($_SERVER["REQUEST_METHOD"] = "POST") {
$email = $_POST["email"];
if(empty($email)){
$emailErr = "Email is required";
}
} else {
$email = input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
// strip data of special characters
function input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(!is_null($firstName) && !empty($firstName)) {
subscription($firstName, $lastName, $mobileNumber, $email);
}
?>
<h2>WELCOME TO THE SIGN UP PAGE!</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
First Name <span class="error"> <?php echo $fNameErr;?></span><br>
<input type="text" name="firstName">
<br><br>
Last Name <span class="error"> <?php echo $lNameErr;?></span><br>
<input type="text" name="lastName">
<br><br>
Mobile Number +1 <span class="error"> <?php echo $mNumberErr;?></span><br>
<input type="text" name="mobileNumber">
<br><br>
Email Address <span class="error"> <?php echo $emailErr;?></span><br>
<input type="text" name="email">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>Your input</h2>";
echo $fName;
echo "<br>";
echo $lName;
echo "<br>";
echo $mNumber;
echo "<br>";
echo $email;
?>
</body>
</html>