-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-form.php
More file actions
150 lines (123 loc) · 3.97 KB
/
generate-form.php
File metadata and controls
150 lines (123 loc) · 3.97 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
session_start();
if (!isset($_SESSION['HospitalID'])) {
header('Location: index.php');
exit();
}
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BIS Dashboard - Asiri Hospital Colombo</title>
<link rel="stylesheet" href="./src/css/generate-form.css" />
<style>
.breadcrumb {
padding: 15px 30px;
padding-bottom: 0%;
background: #eee;
font-size: 14px;
text-decoration: none;
}
.breadcrumb a {
text-decoration: none;
}
</style>
</head>
<body>
<header>
<div class="logo">BIS Dashboard - Asiri Hospital Colombo</div>
<a href="?logout=true" class="logout">Logout</a>
</header>
<nav class="breadcrumb">
<a href='index.php'><b> Dashboard </b> </a> / Approved Registration Forms
</nav>
<div class="container">
<h1>Generate Birth Form</h1>
<p>Please fill all required information</p>
<div id="section1">
<input type="text" id="nic" placeholder="Parent NIC Number *" required pattern="^([0-9]{9}[vVxX]|[0-9]{12})$" title="Enter a valid NIC: 9 digits + V/X or 12 digits" />
<input type="text" id="name" placeholder="Parent Full Name *" required />
<input type="email" id="email" placeholder="Parent Email Address *" required />
</div>
<button onclick="generateLink()">Generate & Send Link</button>
<div id="success" class="success-message" style="display:none;">
✔ Success! The form link has been generated and sent to the provided email address.
</div>
<div id="error" class="error-message" style="display:none;">
❌ Something went wrong! The email could not be sent.
</div>
</div>
<footer>
Register General's Department - Sri Lanka
</footer>
<script>
function validateSection(sectionNum) {
const section = document.getElementById(`section${sectionNum}`);
const inputs = section.querySelectorAll('input[required], select[required], textarea[required]');
let firstInvalid = null;
for (const input of inputs) {
if (input.offsetParent === null) continue; // skip hidden
if (!input.checkValidity()) {
firstInvalid = input;
break;
}
}
if (firstInvalid) {
firstInvalid.reportValidity();
firstInvalid.scrollIntoView({
behavior: 'smooth',
block: 'center'
});
return false;
}
return true;
}
function generateLink() {
const nic = document.getElementById("nic").value.trim();
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const successBox = document.getElementById("success");
const errorBox = document.getElementById("error");
successBox.style.display = "none";
errorBox.style.display = "none";
const isValid = validateSection(1);
if (!isValid) return;
fetch("inc/insert-form.php", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
ParentsName: name,
Email: email,
NIC: nic
})
})
.then(async res => {
const data = await res.text();
try {
const json = JSON.parse(data);
if (!res.ok) throw new Error(json.error || json.warning || "Unknown error");
successBox.style.display = "block";
console.log("Success:", json.message || json.warning);
} catch (e) {
errorBox.style.display = "block";
console.error("Parse error:", e.message);
}
})
.catch(err => {
errorBox.style.display = "block";
console.error("Request error:", err.message);
});
}
</script>
</body>
</html>