/
userInitialForm.php
223 lines (192 loc) · 6.6 KB
/
userInitialForm.php
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
include_once 'phpsqlsearch_dbinfo.php';
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles.css" />
<title>Describe Need</title>
</head>
<body>
<?php
//Connect to database
$link = mysql_connect($hostname, $username, $password);
//If connection fails
if(!$link){
die("Connection Error:".mysql_error());
}
$db_selected = mysql_select_db($database,$link);
?>
<div class="wrapper">
<header>
<img src="rsz_cmlogo.jpg"/>
<nav>
<ul>
<li><a href="landingPage.php">Home</a></li>
<li><a href="userInitialForm.php" class="current">Donate</a></li>
</ul>
</nav>
</header>
</div>
<!-- Form adapted from https://www.w3schools.com/howto/howto_css_responsive_form.asp -->
<div class="containerForm">
<div class="serviceArea">
<h3>We Currently Only Serve Seattle, WA Area</h3>
</div>
<form action = "userInitialForm.php" method = "post">
<div class="row">
<div class="col-25">
<label for="firstName">First Name:</label>
</div>
<div class="col-75">
<input type = "text" id="firstName" name="firstName" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="lastName">Last Name:</label>
</div>
<div class="col-75">
<input type = "text" id="lastName" name="lastName" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="email">Email Address:</label>
</div>
<div class="col-75">
<input type = "email" id="email" name="email">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="need">Please Describe Need:</label>
</div>
<div class="col-75">
<input type = "text" id="need" name="need" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="needType">Please Select Apropriate Need Category:</label>
</div>
<div class="col-75">
<?php
//Code from https://stackoverflow.com/questions/8022353/how-to-populate-html-dropdown-list-with-values-from-database
$conn = new mysqli($hostname, $username, $password, $database)
or die ('Cannot connect to db');
$result = $conn->query("select id, name from categories");
echo "<select name='needType'>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['name'];
echo '<option value="'.$name.'">'.$name.'</option>';
}
echo "</select>";
?>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="makeDonation">Select If Making A Donation:</label>
</div>
<div class="col-75">
<label>Yes</label>
<input type ="radio" name="makeDonation" value="Yes">
<label>No</label>
<input type ="radio" name="makeDonation" value="No"><br>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="requireService">Will Service Be Required?:</label>
</div>
<div class="col-75">
<label>Yes</label>
<input type ="radio" name="requireService" value="Yes">
<label>No</label>
<input type ="radio" name="requireService" value="No"><br>
</div>
</div>
<!--Your Latitude -->
<input type ="hidden" name="latitude" id="latitude" value="47.607055">
<!--<br>
Your longitude-->
<input type="hidden" name="longitude" id="longitude" value="-122.329033">
<!--<br> -->
<div class="row">
<input type ="submit" name="Submit"><br>
</div>
</form>
</div>
<!--<script>
//Code attribution: Learning PHP, MySQL & JavaScript by Robin Nixon (O'Reilly)
/* if (typeof navigator.geolocation == 'undefined')
alert("Geolocation not supported.");
else
navigator.geolocation.getCurrentPosition(granted, denied);
function granted(position){
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var outputlat = document.getElementById('latitude');
var outputlong = document.getElementById('longitude');
outputlat.value=lat;
outputlong.value=lon;
alert("Permission Granted. You are at location:\n\n"
+ lat + ", " + lon +
"\n\nClick 'OK' to load Google Maps with your location");
//window.location.replace("https://www.google.com/maps/@"
//+ lat + "," + lon + ",14z")
}
function denied(error){
var message
switch(error.code){
case 1: message = 'Permission Denied'; break;
case 2: message = 'Position Unavailable'; break;
case 3: message = 'Operation Timed Out'; break;
case 4: message = 'Unknown Error'; break;
}
alert("Geolocation Error: " + message);
} */
</script> -->
<?php
$outputlat=$_POST['latitude'];
$outputlon=$_POST['longitude'];
$outputNeedType=$_POST['needType'];
if(isset($_POST['Submit'])){
$query= "INSERT INTO `ticket` (`firstName`,`lastName`,`email`,`description`,`needType`,`serviceRequired`,`willDonate`,`lattitude`,`longitude`)
VALUES ('$_POST[firstName]', '$_POST[lastName]', '$_POST[email]', '$_POST[need]', '$_POST[needType]', '$_POST[requireService]', '$_POST[makeDonation]','$_POST[latitude]', '$_POST[longitude]')";
//If query fails
if(!mysql_query($query)){
die('Error:'.mysql_error());
}
else{
$ticketCreated = "Ticket Created";
echo $ticketCreated;
}
}
?>
<!--redirect to locationList.php -->
<!--<script type="text/javascript">
var posted = "<?php echo $ticketCreated ?>";
if(posted === "Ticket Created"){
location.href = 'locationList.php';
}
</script>-->
<div class="containerForm">
<form action="locationList.php" method="POST">
<input type="hidden" name="outputNeedType" value="<?php echo $outputNeedType; ?>">
<div class="row">
<div class="col-25">
<label for="submit">Click Go To Map Button To Be Matched With An Organization</label>
</div>
<div class="col-75">
<button type="submit" id="mapBtn">Go To Map</button>
</div>
</div>
</form>
</div>
</body>
</html>