-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 1.24 KB
/
script.js
File metadata and controls
39 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Contact form handler
document.getElementById('contactForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = {
name: document.getElementById('name').value,
email: document.getElementById('email').value,
message: document.getElementById('message').value
};
// BUG: Email validation is not working properly
if (!formData.email.includes('@')) {
alert('Please enter a valid email');
return;
}
// TODO: Add loading spinner here
// Simulate API call with callback (should be converted to async/await)
submitForm(formData, function(error, response) {
if (error) {
document.getElementById('result').innerHTML = 'Error: ' + error;
} else {
document.getElementById('result').innerHTML = 'Success: ' + response;
}
});
});
// Callback-based form submission (should be converted to async/await)
function submitForm(data, callback) {
setTimeout(function() {
// BUG: No input sanitization - XSS vulnerability
if (Math.random() > 0.5) {
callback(null, 'Message sent successfully!');
} else {
callback('Network error', null);
}
}, 2000);
}