Files
marmeladenladen/js/registration.js
StockiP 9e28e83146 hm?
2022-05-02 10:13:28 +02:00

46 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;
}
}