47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
const password = document.getElementById('password');
|
|
const password2 = document.getElementById('password2');
|
|
|
|
|
|
password2.addEventListener('change', checkPassword);
|
|
const form = document.getElementById('marmeladenLadenRegisterForm');
|
|
form.addEventListener('submit', register);
|
|
|
|
async function register(event) {
|
|
event.preventDefault();
|
|
|
|
//check password with checkPassword function
|
|
if (checkPassword()) {
|
|
//get form data
|
|
const formData = new FormData(form);
|
|
//create object with form data
|
|
const data = {};
|
|
formData.forEach((value, key) => data[key] = value);
|
|
|
|
//send data to php with Ajax
|
|
$.ajax({
|
|
url: '../logic/serviceLogic.php',
|
|
type: 'POST',
|
|
data: {method: 'register', data: data},
|
|
datatype: 'json',
|
|
success: function (response) {
|
|
if (response === 'success') {
|
|
window.location.replace('index.html');
|
|
} else {
|
|
alert(response);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function checkPassword() {
|
|
if (password.value != password2.value) {
|
|
password2.setCustomValidity('Passwords do not match');
|
|
return false;
|
|
} else {
|
|
password2.setCustomValidity('');
|
|
return true;
|
|
}
|
|
} |