-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-side.html
120 lines (102 loc) · 2.89 KB
/
client-side.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<title>POST Request Example</title>
<style>
body {
background-color: #eee;
font-family: Arial, sans-serif;
color: #222;
}
h1 {
text-align: center;
font-size: 36px;
margin-bottom: 40px;
}
form {
display: none;
background-color: #fff;
border-radius: 10px;
padding: 20px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
max-width: 400px;
margin: 0 auto;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="text"],
input[type="file"],
button[type="submit"] {
display: block;
width: 100%;
margin-bottom: 10px;
padding: 10px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 18px;
}
button[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
}
button[type="submit"]:disabled {
background-color: #ff0000;
}
button.toggle-form {
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>POST Request Example</h1>
<button class="toggle-form" id="submit-button">Open Form</button>
<form id="my-form">
<label>Text: Name email phone number and you message</label>
<input type="text" name="text" placeholder="Name email phone number and you message">
<label>File: The server will not receive more than 49mb."</label>
<input type="file" name="file">
<button type="submit">Submit</button>
</form>
<script>
const form = document.querySelector('#my-form');
const toggleFormButton = document.querySelector('.toggle-form');
const submitButton = document.querySelector('#submit-button');
let isSubmitting = false;
toggleFormButton.addEventListener('click', () => {
form.style.display = (form.style.display === 'none') ? 'block' : 'none';
});
form.addEventListener('submit', async (e) => {
e.preventDefault();
// Only allow one submission at a time
if (isSubmitting) {
return;
}
isSubmitting = true;
submitButton.disabled = true;
const formData = new FormData(form);
const response = await fetch('https://easy-opposite-flute.glitch.me/', {
method: 'POST',
body: formData
});
const data = await response.text();
console.log(data);
// Re-enable the button after 10 seconds
setTimeout(() => {
isSubmitting = true;
submitButton.disabled = true;
}, 10000);
});
</script>
</body>
</html>