Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa6e07b

Browse files
committed
hotfix form sending
1 parent e5a820a commit aa6e07b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

script.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ form.addEventListener('submit', (event) => {
7676
if (validation()) {
7777
buttonSubmitForm.classList.add('form__submit_sending');
7878
buttonSubmitForm.textContent = 'Sending...';
79-
const formName = document.getElementById('name').value;
80-
const formEmail = document.getElementById('email').value;
81-
const formText = document.getElementById('textarea').value;
79+
const {formName, formEmail, formText} = event.currentTarget.elements;
8280
console.log(formName, formEmail, formText);
83-
let response = fetch('http://localhost:3000', {
81+
fetch('https://jsonplaceholder.typicode.com/posts', {
8482
method: 'POST',
8583
mode:'no-cors',
8684
headers: {
@@ -91,14 +89,17 @@ form.addEventListener('submit', (event) => {
9189
email: formEmail,
9290
text: formText
9391
})
94-
});
95-
if (response.ok) {
92+
})
93+
.then(function() {
9694
buttonSubmitForm.classList.add('form__submit_success');
9795
buttonSubmitForm.textContent = 'Sent!';
98-
} else {
99-
alert('Oops... Something went wrong :(');
100-
closeForm();
101-
}
96+
form.reset();
97+
setTimeout(function() {
98+
buttonSubmitForm.classList.remove('form__submit_success');
99+
buttonSubmitForm.classList.remove('form__submit_sending');
100+
buttonSubmitForm.textContent = 'Send';
101+
}, 2000);
102+
});
102103
}
103104
});
104105

0 commit comments

Comments
 (0)