-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_form.html
159 lines (135 loc) · 5.43 KB
/
query_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
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
151
152
153
154
155
156
157
158
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>Query Form</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<link rel="stylesheet" href="style.css">
<style>
body {
background-color: #f8f9fa;
font-family: sans-serif;
}
.navbar {
background-color: #343a40; /* Dark background color for the navbar */
color: #ffffff; /* Light text color */
}
#queryForm {
max-width: 600px;
width: 60%;
margin: auto;
margin-top: 50px;
}
.form-group {
margin-bottom: 20px;
}
@media screen and (max-width: 600px) {
#queryForm {
max-width: 600px;
width: 100%;
margin: auto;
margin-top: 50px;
}
}
</style>
</head>
<body>
<div class="topbar">
<div class="topbar-content">
<span class="topbar-text">IIT Gandhinagar</span>
<img src="iitgn_logo.png" alt="IIT Gandhinagar Logo" class="topbar-logo">
</div>
</div>
<h2 class="text-center" style="text-align: center;
padding: 20px;
margin-top: 30px;">
Fill the Query Form
</h2>
<form action="query_form.php" method="post" id="queryForm">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" class="form-control" maxlength="100" required>
</div>
<div class="form-group">
<label for="department">Department:</label>
<input type="text" id="department" name="department" class="form-control" maxlength="50" required>
</div>
<div class="form-group">
<label for="queryType">Query Type:</label>
<select name="queryType" id="queryType" class="form-control" onchange="showFields(this.value)">
<option value="">Select...</option>
<option value="Social Media">Social Media</option>
<option value="Websites">Websites</option>
<option value="PhotoVideography">Photo/Videography</option>
</select>
</div>
<div id="SocialMediaFields" style="display:none;" class="form-group">
<label for="imageVideo">Image/Video:</label>
<input type="text" id="imageVideo" name="imageVideo" class="form-control">
<label for="description">Description:</label>
<textarea id="description" name="description" form="queryForm" class="form-control"></textarea>
</div>
<div id="WebsitesFields" style="display:none;" class="form-group">
<label for="websiteLink">Link to the Website:</label>
<input type="text" id="websiteLink" name="websiteLink" class="form-control">
<label for="description">Description:</label>
<textarea id="description" name="description" form="queryForm" class="form-control"></textarea>
</div>
<div id="PhotoVideographyFields" style="display:none;" class="form-group">
<label for="description">Description:</label>
<textarea id="description" name="description" form="queryForm" class="form-control"></textarea>
</div>
<input type="submit" value="Submit Query" class="btn btn-primary">
</form>
<script>
function showFields(queryType) {
document.getElementById('SocialMediaFields').style.display = 'none';
document.getElementById('WebsitesFields').style.display = 'none';
document.getElementById('PhotoVideographyFields').style.display = 'none';
if (queryType === 'Social Media') {
document.getElementById('SocialMediaFields').style.display = 'block';
} else if (queryType === 'Websites') {
document.getElementById('WebsitesFields').style.display = 'block';
} else if (queryType === 'PhotoVideography') {
document.getElementById('PhotoVideographyFields').style.display = 'block';
}
}
function showSuccessMessage() {
Swal.fire({
icon: 'success',
title: 'Success!',
text: 'Query submitted successfully.',
});
}
// Function to show SweetAlert error message
function showErrorMessage() {
Swal.fire({
icon: 'error',
title: 'Error!',
text: 'Query submission failed. Please try again.',
});
}
function submitForm() {
// Prevent the default form submission
event.preventDefault();
// Get form data
var formData = $('#queryForm').serialize();
// Submit the form using Ajax
$.ajax({
type: 'POST',
url: 'query_form.php',
data: formData,
success: function () {
// If the submission is successful, show the success message
showSuccessMessage();
},
error: function () {
// If there's an error, show the error message
showErrorMessage();
}
});
}
// Attach the submitForm function to the form submission event
$('#queryForm').submit(submitForm);
</script>
</body>