56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
const email = document.getElementById('email');
|
|
const password = document.getElementById('password');
|
|
const password2 = document.getElementById('password2');
|
|
password2.addEventListener('change', checkPassword);
|
|
const form = document.getElementById('marmeladenLadenRegisterForm');
|
|
form.addEventListener('submit', register);
|
|
|
|
|
|
function register() {
|
|
|
|
|
|
$.ajax({
|
|
url: 'php/registration.php',
|
|
type: 'POST',
|
|
data: {
|
|
email: email.value,
|
|
password: password.value,
|
|
password2: password2.value
|
|
},
|
|
success: function (data) {
|
|
if (data == 'success') {
|
|
window.location.href = 'index.html';
|
|
} else {
|
|
alert(data);
|
|
}
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
var formData = new FormData(form);
|
|
const jSONdata = JSON.stringify(Object.fromEntries(formData));
|
|
|
|
//print elements of jSONdata
|
|
console.log(jSONdata);
|
|
|
|
|
|
function checkPassword() {
|
|
if (password.value != password2.value) {
|
|
password2.setCustomValidity('Passwords do not match');
|
|
return false;
|
|
} else {
|
|
password2.setCustomValidity('');
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function checkemail() {
|
|
if (email.value != '') {
|
|
email.setCustomValidity('');
|
|
return true;
|
|
} else {
|
|
email.setCustomValidity('Email is required');
|
|
return false;
|
|
}
|
|
} |