/
graffiti.html
executable file
·100 lines (83 loc) · 3.36 KB
/
graffiti.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
<!DOCTYPE html>
<html>
<head>
<title>Graffiti</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div class="heading">
<h1>Graffiti</h1>
<h4>Add your voice to the Pset6-Alt graffiti wall</h4>
</div>
<div class="card">
<!-- Don't change the id. Our JS script below is looking for "slackForm". -->
<form id="slackForm" action="https://hooks.slack.com/services/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" method="post">
<!-- TODO: add the necessary fields, action, submit button, etc -->
<div class="label">
<label for="label" id="username">username</label>
</div>
<div>
<input type="text" name="username"/>
</div>
<br>
<div class="label">
<label for="label" id="icon_emoji">avatar</label>
</div>
<div class= "dropdown">
<select name = "icon_emoji">
<option value = "None">Pick One</option>
<option value = ":unicorn_face:">Magical</option>
<option value = ":squirrel:">Squirrely</option>
<option value = ":sweat_drops:">Sweating</option>
<option value = ":ambulance:">Call 911</option>
</select>
</div>
<br>
<div class="label">
<label for="label" id="text">message</label>
</div>
<div>
<input type="text" name="text"/>
</div>
<br>
<div>
<button type="submit" value="submit">Scrawl on the Wall!</button>
</div>
</form>
</div>
<!-- here we include some javascript: first a few libraries... -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<!-- ...and then our own script -->
<script type="text/javascript">
// first get a reference to the form
var slackForm = document.getElementById("slackForm");
// right before the form submits, execute the function called populatePayloadField
slackForm.onsubmit = populatePayloadField;
function populatePayloadField() {
// convert form fields into a JSON string
var formData = getFormData();
delete formData.payload;
var jsonString = JSON.stringify(formData);
// create a new hidden input and add it to the form
var payloadInput = document.createElement("input");
payloadInput.setAttribute("type", "hidden");
payloadInput.setAttribute("name", "payload");
payloadInput.setAttribute("value", jsonString);
console.log(payloadInput);
slackForm.appendChild(payloadInput);
console.log(slackForm);
}
// a helper function to return a javascript object containing all the form's fields
function getFormData() {
var object = {};
var fields = $("#slackForm").serializeArray();
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
object[field.name] = field.value;
}
return object;
}
</script>
</body>
</html>