Created
December 6, 2024 13:56
-
-
Save Aminigbo/028bea95c3b6a8b3d32716348082f994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Sign-Up Form</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
margin: 20px; | |
} | |
h1 { | |
color: #333; | |
} | |
form { | |
max-width: 400px; | |
margin: 0 auto; | |
} | |
label { | |
display: block; | |
margin-bottom: 5px; | |
font-weight: bold; | |
} | |
input { | |
width: 100%; | |
padding: 10px; | |
margin-bottom: 15px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
} | |
button { | |
padding: 10px 20px; | |
font-size: 1em; | |
color: #fff; | |
background-color: #007BFF; | |
border: none; | |
cursor: pointer; | |
border-radius: 5px; | |
} | |
button:hover { | |
background-color: #0056b3; | |
} | |
#response { | |
margin-top: 20px; | |
font-size: 1em; | |
color: green; | |
} | |
#error { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Sign-Up Form</h1> | |
<form id="signUpForm"> | |
<label for="name">Name</label> | |
<input type="text" id="name" placeholder="Enter your name" required /> | |
<label for="email">Email</label> | |
<input type="email" id="email" placeholder="Enter your email" required /> | |
<label for="phone">Phone</label> | |
<input type="text" id="phone" placeholder="Enter your phone number" required /> | |
<label for="password">Password</label> | |
<input type="password" id="password" placeholder="Enter your password" required /> | |
<label for="fcmToken">FCM Token</label> | |
<input type="text" id="fcmToken" placeholder="Enter FCM token" required /> | |
<button type="submit">Sign Up</button> | |
</form> | |
<div id="response"></div> | |
<div id="error"></div> | |
<script> | |
document.getElementById("signUpForm").addEventListener("submit", async (e) => { | |
e.preventDefault(); | |
const name = document.getElementById("name").value; | |
const email = document.getElementById("email").value; | |
const phone = document.getElementById("phone").value; | |
const password = document.getElementById("password").value; | |
const fcmToken = document.getElementById("fcmToken").value; | |
const myHeaders = new Headers(); | |
myHeaders.append("Content-Type", "application/json"); | |
const raw = JSON.stringify({ | |
name, | |
email, | |
phone, | |
password, | |
fcmToken, | |
}); | |
const requestOptions = { | |
method: "POST", | |
headers: myHeaders, | |
body: raw, | |
redirect: "follow", | |
}; | |
try { | |
let baseURL = "https://i-voucher-server.vercel.app//APP/" | |
const response = await fetch(`${baseURL}auth/sign-up`, requestOptions); | |
if (response.ok) { | |
const result = await response.text(); | |
console.log(result) | |
document.getElementById("response").textContent = "Success: " + result; | |
document.getElementById("error").textContent = ""; | |
} else { | |
const error = await response.text(); | |
document.getElementById("error").textContent = "Error: " + error; | |
document.getElementById("response").textContent = ""; | |
} | |
} catch (error) { | |
document.getElementById("error").textContent = "Network Error: " + error.message; | |
document.getElementById("response").textContent = ""; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment