-
Notifications
You must be signed in to change notification settings - Fork 167
/
register.html
67 lines (67 loc) · 2.38 KB
/
register.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" type="text/css" href="./style3.css">
<script type="text/javascript" src="script3.js"></script>
</head>
<body>
<div class="main">
<h1 class="form-title">Medical Website</h1>
<form id="registerForm">
<class="main-user-info">
<div class="user-input-box">
<label for="name">Name : </label>
<input type="text" id="name" name="name" placeholder="Enter your name">
</div>
<div class="user-input-box">
<label for="email">E-mail : </label>
<input type="email" id="email" name="email" placeholder="Enter your mail id">
</div>
<div class="user-input-box">
<label for="password">password : </label>
<input type="password" id="password" name="password" placeholder="Enter password">
</div>
<div class="form-submit-button">
<input type="submit" value="Register">
</div>
<div class="register">
<a href="login.html">Back to login</a>
</div>
</div>
</form>
</div>
<script>
document.getElementById('registerForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
fetch('/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: formData.get('name'),
email: formData.get('email'),
password: formData.get('password'),
role: 'user'
}),
})
.then(response => response.json())
.then(data => {
if (data.redirect) {
window.location.href = data.redirect;
} else {
alert(data.message);
}
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred during registration');
});
});
</script>
</body>
</html>