-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.html
81 lines (73 loc) · 2.55 KB
/
signup.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sign Up to Bio Care</title>
<link rel="stylesheet" href="signup.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
<div class="content">
<div class="left">
<h1>Sign Up</h1>
<form id="signupForm">
<div class="inputfield">
<input type="text" id="name" name="fullName" required />
<span>Full Name</span>
</div>
<div class="inputfield">
<input type="text" id="mobile" name="mobile" required />
<span>Mobile Number</span>
</div>
<div class="inputfield">
<input type="password" id="password" name="password" required />
<span>Password</span>
</div>
<button type="submit">Sign Up</button>
</form>
</div>
<div class="right">
<h1>Already Have an Account?</h1>
<a href="login.html"><button>Log In</button></a>
</div>
</div>
<script>
document
.getElementById("signupForm")
.addEventListener("submit", async function (e) {
e.preventDefault(); // Prevent traditional form submission
// Collect the form data
const name = document.getElementById("name").value;
const mobile = document.getElementById("mobile").value;
const password = document.getElementById("password").value;
if (!name || !mobile || !password) {
alert("All fields are required!");
return;
}
// Send data to the backend
try {
const response = await fetch(
"https://bio-care.onrender.com/signup",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name, mobile, password }),
}
);
const data = await response.json(); // Always parse JSON response
// Show message in a popup
alert(data.message);
if (response.ok) {
// Save login status in localStorage
localStorage.setItem("loggedIn", "true");
// Redirect to index.html (home page)
window.location.href = "index.html";
}
} catch (err) {
alert("An error occurred: " + err.message);
}
});
</script>
</body>
</html>