-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
74 lines (59 loc) · 2.34 KB
/
Copy pathindex.html
File metadata and controls
74 lines (59 loc) · 2.34 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
<section class="contact-form">
<h1>Send Me a Message</h1>
<p>Use this handy contact form to get in touch with me.</p>
<form>
<div class="input-group">
<input id="salutation-mr" name="salutation" type="radio" value="Mr."/>
<label class="inline" for="salutation-mr">Mr.</label>
<input id="salutation-mrs" name="salutation" type="radio" value="Mrs."/>
<label class="inline" for="salutation-mrs">Mrs.</label>
<input id="salutation-ms" name="salutation" type="radio" value="Ms."/>
<label class="inline" for="salutation-ms">Ms.</label>
</div>
<div class="input-group">
<label for="name">Full Name</label>
<input id="name" name="name" type="text"/>
</div>
<div class="input-group">
<label for="email">Email Address</label>
<input id="email" name="email" type="email"/>
</div>
<div class="input-group">
<label for="subject">How can I help you?</label>
<select id="subject" name="subject">
<option>I have a problem.</option>
<option>I have a general question.</option>
</select>
</div>
<div class="input-group">
<label for="message">Enter a Message</label>
<textarea id="message" name="message" rows="6" cols="65"></textarea>
</div>
<div class="input-group">
<p class="group-label">Please send me:</p>
<input id="snacks-pizza" name="snacks" type="checkbox" value="pizza"/>
<label class="inline" for="snacks-pizza">Pizza</label>
<input id="snacks-cake" name="snacks" type="checkbox" value="cake"/>
<label class="inline" for="snacks-cake">Cake</label>
</div>
<input name="secret" type="hidden" value="1b3a9374-1a8e-434e-90ab-21aa7b9b80e7"/>
<button type="submit">Send It!</button>
</form>
<script>
function handleFormSubmit(event) {
event.preventDefault();
const data = new FormData(event.target);
const formJSON = Object.fromEntries(data.entries());
// for multi-selects, we need special handling
formJSON.snacks = data.getAll('snacks');
const results = document.querySelector('.results pre');
results.innerText = JSON.stringify(formJSON, null, 2);
}
const form = document.querySelector('.contact-form');
form.addEventListener('submit', handleFormSubmit);
</script>
</section>
<div class="results">
<h2>Form Data</h2>
<pre></pre>
</div>