-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_password.php
79 lines (64 loc) · 2.69 KB
/
change_password.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form id="formID" action="" method="post">
<div class="error" id="error"></div>
<div class="input_field">
<label for="currentPass">Mật khẩu hiện tại: </label>
<input type="password" name="currentPass" id="currentPass" autocomplete="off">
</div>
<div class="input_field">
<label for="newPass">Mật khẩu mới: </label>
<input type="password" name="newPass" id="newPass" autocomplete="off">
</div>
<div class="input_field">
<input type="submit" name="submitBtn" id="submitBtn" value="Cập nhật">
</div>
</form>
<a href="edit_user_profile.php"><button>Quay về</button></a>
<script>
const submitBtn = document.getElementById("submitBtn");
const form = document.getElementById("formID");
const errorText = document.getElementById("error");
submitBtn.addEventListener("click", function(e) {
e.preventDefault();
submitBtn.disabled = true;
const currentPass = document.getElementById("currentPass");
const newPass = document.getElementById("newPass");
// collect data
const data = {};
data.currentPass = currentPass.value;
data.newPass = newPass.value;
//console.log(JSON.stringify(data));
send_data(data, "change_password");
});
function send_data(data, type) {
let xml = new XMLHttpRequest();
xml.addEventListener("load", function() {
if (xml.readyState == 4 || xml.status == 200) { // everything good
let message = xml.responseText;
if (message == "yes") {
alert("Cập nhật thành công!");
// chuyển hướng qua trang khác
location.href = "edit_user_profile.php";
} else {
errorText.textContent = message;
errorText.style.display = "block";
}
submitBtn.disabled = false; // after done sending the data, enable the button
}
});
// send data
data.type_of_data = type;
let data_string = JSON.stringify(data); // cannot send object so turn the obj to string
xml.open("POST", "backend/handle_data.php", true);
xml.send(data_string);
}
</script>
</body>
</html>