added logic / Form stuff
This commit is contained in:
19
js/app.js
Normal file
19
js/app.js
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
$(document).ready(function () {
|
||||
$('#mmlMainContent').load('../components/homepage.html');
|
||||
$('#top_nav_bar').load('../components/top_nav.html');
|
||||
$('#main_nav_bar').load('../components/main_nav.html', function () {
|
||||
var _a, _b, _c;
|
||||
(_a = document.getElementById('registerLink')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', function () {
|
||||
$('#mmlMainContent').load('../components/register.html');
|
||||
});
|
||||
(_b = document.getElementById('homeLink')) === null || _b === void 0 ? void 0 : _b.addEventListener('click', function () {
|
||||
$('#mmlMainContent').load('../components/homepage.html');
|
||||
});
|
||||
(_c = document.getElementById('loginLink')) === null || _c === void 0 ? void 0 : _c.addEventListener('click', function () {
|
||||
$('#mmlMainContent').load('../components/login.html');
|
||||
});
|
||||
});
|
||||
$('#marmeladenladen_footer').load('../components/footer.html');
|
||||
$('#marmeladenladen_search').load('../components/modal.html');
|
||||
});
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#mmlMainContent').load('../components/homepage.html');
|
||||
$('#top_nav_bar').load('../components/top_nav.html');
|
||||
@@ -14,7 +12,6 @@ $(document).ready(function() {
|
||||
$('#mmlMainContent').load('../components/login.html');
|
||||
},);
|
||||
});
|
||||
$('#mmlMainContent').load('../components/ftProducts.html');
|
||||
$('#marmeladenladen_footer').load('../components/footer.html');
|
||||
$('#marmeladenladen_search').load('../components/modal.html');
|
||||
});
|
||||
|
||||
@@ -1,41 +1,42 @@
|
||||
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);
|
||||
|
||||
async function register(event) {
|
||||
event.preventDefault();
|
||||
|
||||
function register() {
|
||||
//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);
|
||||
|
||||
|
||||
$.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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var formData = new FormData(form);
|
||||
const jSONdata = JSON.stringify(Object.fromEntries(formData));
|
||||
|
||||
|
||||
//print elements of jSONdata
|
||||
console.log(jSONdata);
|
||||
|
||||
|
||||
function checkPassword() {
|
||||
async function checkPassword() {
|
||||
if (password.value != password2.value) {
|
||||
password2.setCustomValidity('Passwords do not match');
|
||||
return false;
|
||||
@@ -43,14 +44,4 @@ function checkPassword() {
|
||||
password2.setCustomValidity('');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function checkemail() {
|
||||
if (email.value != '') {
|
||||
email.setCustomValidity('');
|
||||
return true;
|
||||
} else {
|
||||
email.setCustomValidity('Email is required');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user