Skip to content

Commit

Permalink
Update send.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sohez authored Sep 1, 2023
1 parent d4d6e31 commit fba2354
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions script/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ var form = document.getElementById("formid");
function setresText(res) {
document.getElementById("checker").innerText = res;
}

form.addEventListener("submit", function (e) {
e.preventDefault();
setresText("Sending msg..");
var msg = sendMessage();
});

function isValid(email) {
//check email is formated
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
Expand All @@ -25,24 +27,30 @@ function sendMessage() {
return false;
}

$.ajax({
url: 'https://script.google.com/macros/s/AKfycbwkjI7POBip0D3idUWfZwmdN4bV9TPfkfUWLwWZbu_rxDWSM5_F5VI1jVAXCKlRt0ykAg/exec',
type: 'post',
data: $('#formid').serialize(),
success: function () {
//if form submited
setresText("Msg Sended !");
setTimeout(function () {
formreset();
}, 2000);
},
error: function () {
//if form not submit
setresText("Somthing Error retry!");
}
});
var data = new FormData();
data.set('Name','@PORTFOLLIO')
data.set('Email', email);
data.set('Request', message);

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://script.google.com/macros/s/AKfycbwkjI7POBip0D3idUWfZwmdN4bV9TPfkfUWLwWZbu_rxDWSM5_F5VI1jVAXCKlRt0ykAg/exec', true);

xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
setresText("Message Sended !");
setTimeout(function () {
formreset();
}, 2000);
}
}
xhr.onerror = function(){
setresText("Somthing Error !");
}
xhr.send(data);

return true;
}

function formreset() {
//for empty all values
setresText("");
Expand Down

0 comments on commit fba2354

Please sign in to comment.