-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.js
112 lines (92 loc) · 3.38 KB
/
signup.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict'
function signUpBtn() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function (checkbox) {
if (checkbox.checked) {
if (checkbox.id === 'student') {
window.location.href = 'student.html';
/*fetch('http://localhost/neolearn-backend/index.php/students')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
// Work with the data
console.log(data);
})
.catch(error => {
// Handle errors
console.error('There was a problem with the fetch operation:', error);
});*/
}
else if (checkbox.id === 'teacher') {
window.location.href = 'teacher.html';
}
}
});
}
function handleCheckboxClick(clickedCheckboxId) {
const checkboxes = document.querySelectorAll('.form-check-input');
checkboxes.forEach(function (checkbox) {
if (checkbox.id !== clickedCheckboxId) {
checkbox.checked = false;
}
});
}
/*'use strict';
function signUpBtn() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function (checkbox) {
if (checkbox.checked) {
const userDetails = getUserDetails();
if (checkbox.id === 'student') {
// Assuming 'createStudent' is your API endpoint for creating students
signUp(userDetails, 'http://localhost/neolearn-backend/index.php/students');
} else if (checkbox.id === 'teacher') {
// Assuming 'createInstructor' is your API endpoint for creating teachers
signUp(userDetails, 'http://localhost/neolearn-backend/index.php/instructors');
}
}
});
}
function getUserDetails() {
const firstName = document.getElementById('firstname').value;
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
return {
firstName: firstName,
username: username,
password: password,
};
}
async function signUp(userDetails, endpoint) {
try {
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userDetails),
});
if (response.ok) {
// Handle success, e.g., redirect to a success page
console.log('User created successfully!');
} else {
// Handle error response
console.error('Failed to create user:', response.status, response.statusText);
}
} catch (error) {
// Handle network or other errors
console.error('Error:', error);
}
}
function handleCheckboxClick(clickedCheckboxId) {
const checkboxes = document.querySelectorAll('.form-check-input');
checkboxes.forEach(function (checkbox) {
if (checkbox.id !== clickedCheckboxId) {
checkbox.checked = false;
}
});
}*/