-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.html
117 lines (110 loc) · 3.91 KB
/
form.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
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Форма для введення даних про лікарню</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.form-container {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
}
.form-container h1 {
margin-bottom: 20px;
font-size: 24px;
text-align: center;
}
.form-container label {
display: block;
margin-bottom: 5px;
}
.form-container input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-container input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.form-container input[type="submit"]:hover {
background-color: #45a049;
}
.error {
color: red;
margin-bottom: 15px;
}
</style>
</head>
<body>
<div class="form-container">
<h1>Введення даних про лікарню</h1>
<form id="hospitalForm">
<div class="error" id="error-message"></div>
<label for="edrpouCode">Код ЄДРПОУ:</label>
<input type="text" id="edrpouCode" name="edrpouCode" required><br>
<label for="facilityCode">Код закладу:</label>
<input type="text" id="facilityCode" name="facilityCode" required><br>
<label for="address">Адреса:</label>
<input type="text" id="address" name="address" required><br>
<input type="submit" value="Надіслати">
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('hospitalForm');
form.addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(form);
const hospitalData = {
edrpouCode: formData.get('edrpouCode'),
facilityCode: formData.get('facilityCode'),
address: formData.get('address')
};
fetch('http://localhost:8080/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(hospitalData)
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to submit form');
}
return response.json();
})
.then(data => {
console.log('Success:', data);
alert('Дані успішно надіслані!');
})
.catch(error => {
console.error('Error:', error);
alert('Сталася помилка при надсиланні форми.');
});
});
});
</script>
</body>
</html>