-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration.html
More file actions
265 lines (248 loc) · 10.8 KB
/
registration.html
File metadata and controls
265 lines (248 loc) · 10.8 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1">
<title>Registration</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- no seperate stylesheet as too many errors -->
<style>
.error {
color: red;
font-size: small;
display:block;
max-width: 150px;
overflow: hidden;
margin-left: 10px;
}
body, html {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
justify-content: center;
display:flex;
}
.container-fluid{
border-radius:25px;
background:transparent;
padding-top:5px;
padding-bottom:5px;
padding-left:40px;
padding-right:40px;
width:fit -content;
border: 1px solid white;
}
.col-auto{
color: white;
font-size: 15px;
margin: 10px;
justify-content: center;
}
body{
background-image: url('https://res.cloudinary.com/djm2h1vqr/image/upload/v1719405949/Untitled_design_sdnkq3.png');
background-size: cover;
background-position: center;
display:flex;
position: relative;
}
.submitbtn{
cursor: pointer;
border: 1px solid whitesmoke;
background-color: transparent;
color: white;
font-size: x-large;
}
.button-container{
display:flex;
justify-content: center;
}
.row-justify-content {
display: flex;
justify-content: space-around;}
.row-justify-content label,
.row-justify-content input {
margin: 0 10px ;
margin-bottom: 5px;
display:block;
}
</style>
</head>
<body>
<header><div class="navbar"></div></header>
<article class="mt-3">
<form id="regform" action="/registration" method="post">
<div class="container-fluid">
<div class="row justify-content">
<div class="col-auto text-center" >
<h2>Register</h2>
</div>
</div>
<br />
<!-- Fname label and field -->
<div class="row-justify-content">
<div class="col-auto text-center">
<label>First Name</label>
<input type="text" name="fname" id="idfname">
<br>
<span id="firstNameError" class="error"></span>
</div>
<br>
<!-- Lname label and field -->
<div class="row justify-content">
<div class="col-auto text-center">
<label>Last Name</label>
<input type="text" name="lname" id="idlname">
<br>
<span id="lastNameError" class="error"></span>
</div>
</div>
</div>
<br>
<!-- Email label and field -->
<div class="row-justify-content">
<div class="col-auto text-center">
<label>Email</label>
<input type="email" name="email" id="idemail">
<br>
<span id="emailError" class="error"></span>
</div>
<br>
<!-- Username label and field -->
<div class="row justify-content">
<div class="col-auto text-center">
<label>Username</label>
<input type="text" name="username" id="iduname">
<br>
<span id="usernameError" class="error"></span>
</div>
</div>
</div>
<br>
<!-- Password label and field -->
<div class="row-justify-content">
<div class="col-auto text-center">
<label>Password</label>
<input type="password" name="password" id="idpword">
<br>
<span id="passwordError" class="error"></span>
</div>
<br>
<!-- Confirm Password label and field -->
<div class="row justify-content">
<div class="col-auto text-center">
<label>Confirm Password</label>
<input type="password" name="cpword" id="idcpword">
<br>
<span id="cpasswordError" class="error"></span>
</div>
</div>
</div>
<br>
<!-- Btn label and field -->
<div class="button-container">
<div class="col-auto text-center">
<button type="submit" class="submitbtn" >Submit</button>
</div>
</div>
<br>
</div>
</div>
</article>
</form>
<script>
const nav = document.querySelector('.navbar')
fetch('navbar.html')
.then(res=>res.text())
.then(data=>{
nav.innerHTML=data;
})
</script>
<script>
document.getElementById('regform').addEventListener('submit', function(event) {
event.preventDefault();
clearErrors();
let hasErrors = false;
// Username Validation
const username = document.getElementById('iduname').value;
const unamePattern = /^[A-Za-z][A-Za-z0-9_]{7,29}$/;
if (!unamePattern.test(username)) {
showError('usernameError', 'Username must be at least 7 characters long');
hasErrors = true;
}
// Email validation
const email = document.getElementById('idemail').value;
const emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
showError('emailError', 'Please enter a valid email address');
hasErrors = true;
}
// Password validation
const password = document.getElementById('idpword').value;
if (password.length < 6) {
showError('passwordError', 'Password must be at least 6 characters long');
hasErrors = true;
}
// Confirm password validation
const confirmPassword = document.getElementById('idcpword').value;
if (password !== confirmPassword) {
showError('cpasswordError', 'Passwords do not match');
hasErrors = true;
}
// First name validation
const firstName = document.getElementById('idfname').value;
if (firstName.trim() === '') {
showError('firstNameError', 'First name is required');
hasErrors = true;
}
// Last name validation
const lastName = document.getElementById('idlname').value;
if (lastName.trim() === '') {
showError('lastNameError', 'Last name is required');
hasErrors = true;
}
// No errors, submit form
if (!hasErrors) {
alert('Form submitted successfully!');
document.getElementById('regform').submit();
}
});
function showError(elementId, errorMessage) {
const errorElement = document.getElementById(elementId);
errorElement.textContent = errorMessage;
}
function clearErrors() {
const errorElements = document.querySelectorAll('.error');
errorElements.forEach(element => element.textContent = '');
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('regform').addEventListener('submit', function(event) {
event.preventDefault();
const username = document.getElementById('username').value.trim();
const email = document.getElementById('email').value.trim();
const fname = document.getElementById('fname').value.trim();
const lname = document.getElementById('lname').value.trim();
const password = document.getElementById('password').value.trim();
fetch('/registration', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, email, fname, lname, password})
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = '/login';
} else {
alert(data.message);
}
})
.catch(error => console.error('Error:', error));
});
});
</script>
</body>
</html>