Skip to content
Snippets Groups Projects
Commit a75b526d authored by maggiezetaa's avatar maggiezetaa
Browse files

add register

parent dc972e04
No related merge requests found
const register = async function (e) {
e.preventDefault();
try {
const username = document.getElementById("username").value;
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
const profilePicture = document.getElementById("profilePicture").files[0];
const formData = new FormData();
formData.append("username", username);
formData.append("email", email);
formData.append("password", password);
formData.append("profilePicture", profilePicture);
const response = await fetch("/register", {
method: "POST",
body: formData,
credentials: "include",
});
if (response.status === 200) {
const result = await response.json();
if (result.success === true) {
alert("Registration success");
window.location.href = "/login.html"; // Redirect to the login page
} else {
alert("Registration failed");
}
} else {
console.log("Request failed");
}
} catch (error) {
console.log(error);
}
};
// Menggunakan event submit pada form untuk menjalankan fungsi register
document.getElementById("registerForm").addEventListener("submit", register);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
<link rel="stylesheet" href="public/css/styles.css">
</head>
<body>
<?php require_once(PROJECT_ROOT_PATH.'/public/components/Navbar.php'); ?>
<h1 id="registerTitle">Register</h1>
<form id="registerForm" enctype="multipart/form-data" method="POST" action="register.php">
<label for="username" id="usernameLabel">Username:</label>
<input type="text" id="username" name="username" required /><br /><br />
<label for="email" id="emailLabel">Email:</label>
<input type="email" id="email" name="email" required /><br /><br />
<label for="password" id="passwordLabel">Password:</label>
<input type="password" id="password" name="password" required /><br /><br />
<label for="profilePicture" id="profilePictureLabel">Profile Picture:</label>
<input type="file" id="profilePicture" name="profilePicture" accept="image/*" required /><br /><br />
<button type="submit" id="registerButton">Register</button>
</form>
</body>
</html>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment