Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Handle submit button
- */
- signUpForm.onsubmit = async (e) => {
- e.preventDefault();
- let isAllowed = true;
- for (let child of signUpForm.children) { //Check all fields
- let value = child.value.toString();
- let isCorrectFlag = (value.length > 0);
- if (child.name === "username" && isCorrectFlag) {
- isCorrectFlag = !(/[^a-zA-zа-яА-Я]/.test(value));
- }
- if (child.name === "email" && isCorrectFlag) {
- isCorrectFlag = /\S+@\S+\.\S+/.test(value);
- }
- if (isCorrectFlag) child.classList.remove("invalid-field");
- else {
- child.classList.add("invalid-field");
- isAllowed = false;
- }
- }
- if (!userPolicy.checked) return; //Check if policy not accepted
- if (!isAllowed) return;
- let ajax = fetch('./fileHandler.php', { //Generate fetch request
- method: 'POST',
- body: new FormData(signUpForm)
- });
- ajax.then(result => result.json().then(jsonResult => { //Make async request
- if (jsonResult.status !== 200) modalContent.innerHTML = jsonResult.message;
- else closeModalWindow();
- }).catch(() => modalContent.innerHTML = errorText)).catch(() => modalContent.innerHTML = errorText); //Catch exceptions
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement