forked from JWHennessey/cfg_ucl
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforms.html
More file actions
459 lines (327 loc) · 29.8 KB
/
forms.html
File metadata and controls
459 lines (327 loc) · 29.8 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<!DOCTYPE html>
<!-- saved from url=(0032)http://code61.org/ocl5/#!1_forms -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Web Fundamentals 5</title>
<meta name="viewport" content="width=device-width">
<!-- Twitter bootstrap basic styles -->
<link rel="stylesheet" href="http://code61.org/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="http://code61.org/bootstrap/css/bootstrap-responsive.css">
<!-- syntax highlighting CSS -->
<link rel="stylesheet" href="http://code61.org/css/syntax.css">
<!-- Google webfont link -->
<link href="./Web Fundamentals 5_files/css" rel="stylesheet" type="text/css">
<!-- Custom CSS -->
<link rel="stylesheet" href="http://code61.org/css/main.css">
<script src="./Web Fundamentals 5_files/jquery-1.10.0.js"></script>
<script type="text/javascript" src="./Web Fundamentals 5_files/bootstrap.js"></script>
<script type="text/javascript" src="./Web Fundamentals 5_files/custom.js"></script>
<style>[touch-action="none"]{ -ms-touch-action: none; touch-action: none; }[touch-action="pan-x"]{ -ms-touch-action: pan-x; touch-action: pan-x; }[touch-action="pan-y"]{ -ms-touch-action: pan-y; touch-action: pan-y; }[touch-action="scroll"],[touch-action="pan-x pan-y"],[touch-action="pan-y pan-x"]{ -ms-touch-action: pan-x pan-y; touch-action: pan-x pan-y; }</style></head>
<body class="" style="">
<div class="container">
<div class="page-header">
<h1>Web Fundamentals 5 <small>HTML Forms</small></h1>
</div>
<div class="tabbable tabs-left">
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a href="http://code61.org/ocl5/#1_forms" data-toggle="tab">Basic forms </a></li>
<li class=""><a href="http://code61.org/ocl5/#2_form_submissions" data-toggle="tab">Form submissions </a></li>
<li class=""><a href="http://code61.org/ocl5/#3_google_forms" data-toggle="tab">Google forms trick </a></li>
<li class=""><a href="http://code61.org/ocl5/#4_more_elements" data-toggle="tab">More form elements </a></li>
<li class=""><a href="http://code61.org/ocl5/#5_homework" data-toggle="tab">Homework </a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="1_forms">
<h2>Basic forms</h2>
<p>A basic html form looks like this:</p>
<div class="highlight"><pre><code class="html"><span class="nt"><form></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'name'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'email'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'submit'</span><span class="nt">></span>
<span class="nt"></form></span>
</code></pre></div>
<p>It has the following features:</p>
<ul>
<li>The whole form is contained with <code><form>...</form></code> tags.</li>
<li>It has two text fields, using <code><input></code> tags.</li>
<li>The input tags are stand-alone tags: they have no closing <code></input></code>.</li>
<li>It has a submit button <code><input type='submit'></code>.</li>
</ul>
<h3 id="forms_with_labels">Forms with labels</h3>
<p>The above form contains only text boxes. A user visiting the form would have no idea what to put in each box. We can fix this with some simple labels:</p>
<div class="highlight"><pre><code class="html"><span class="nt"><form></span>
<span class="nt"><label></span>Name<span class="nt"></label></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'name'</span><span class="nt">></span>
<span class="nt"><label></span>Email<span class="nt"></label></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'text'</span> <span class="na">name=</span><span class="s">'email'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'submit'</span><span class="nt">></span>
<span class="nt"></form></span>
</code></pre></div><div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>
<p>Clone the code for this session:</p>
<p>git clone https://github.com/code61/html_forms.git</p>
</li>
<li>
<p>Open ‘basic_form.html’ in Sublime Text and Chrome.</p>
</li>
</ol>
</div>
</div>
<div class="tab-pane" id="2_form_submissions">
<h2>Form submissions</h2>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Open <code>basic_form.html</code> in Chrome.</li>
<li>Fill in the name and email and click ‘Submit’.</li>
<li>What, if anything, happens?</li>
</ol>
</div>
<h3 id="the_name_property">The name property</h3>
<p>When you clicked the submit button on the basic form, you probably noticed the url change to something like:</p>
<pre><code>file:///Users/tomclose/Documents/Coding/html_forms/basic_form.html?name=tom&email=tom%40example.com</code></pre>
<p>the values that you entered into the form now appear in the url. (The strange <code>%40</code> is code for the <code>@</code> character, which isn’t allowed to appear in URLs.)</p>
<p>The following things happened:</p>
<ol>
<li>The form packaged up the values you gave it. To do this it used the <code>name</code> property of each input tag.</li>
<li>It submitted them to the <strong>same url</strong> you were on.</li>
<li>It did this by appending them to the url as <em>query parameters</em>.</li>
</ol>
<p>The important thing in deciding how to package the values was the <code>name</code> property of the <code><input></code> tag. The tag</p>
<div class="highlight"><pre><code class="html"><span class="nt"><input</span> <span class="na">name=</span><span class="s">'email'</span><span class="nt">></span>
</code></pre></div>
<p>was converted to the name-value pair <code>email=tom%40example.com</code> in the URL.</p>
<p>You can get a better idea of these stages by looking at the ‘Network’ tab on Chrome’s developer tools:</p>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Open Chrome’s developer tools and go to the ‘Network’ tab.</li>
<li>Put some new values into the form and press ‘Submit’ again.</li>
<li>Look at the information in the ‘Network’ tab.</li>
</ol>
</div>
<p>You should see something like the following: <img alt="dev tools form submit get" src="./Web Fundamentals 5_files/dev_tools_form_submit_get.png"></p>
<p>There are two <code>GET</code> requests. The first is to the same page, with the field names and their new values as query parameters. The second is to bootstrap - when your browser reloads the page with the new query paramenters, it finds the <code><link rel='stylesheet' http='bootstrap/css/bootsrap.css' ></code> in the <code><head></code> and so fetches that file too.</p>
<p>You can find out more about the first <code>GET</code> request by clicking on the <code>headers</code> tab: <img alt="dev tools form submit" src="./Web Fundamentals 5_files/dev_tools_form_submit.png"></p>
<p>You should be able to see the names and their values from the input elements.</p>
<h3 id="get_and_post">GET and POST</h3>
<p>In the above example we saw that the browser made two <code>GET</code> requests. <code>GET</code> is the most common <em>http verb</em>. It describes the normal way your browser asks for a webpage (and CSS files, js files, images etc.).</p>
<p>The most important thing about <code>GET</code> requests is that they <strong>shouldn’t change any values on the server</strong>. For this reason they’re not usually used for form submissions, which are generally for providing new data to the server.</p>
<p>We can change the form to submit using a <code>POST</code> request instead.</p>
<div class="highlight"><pre><code class="html"> <span class="nt"><form</span> <span class="na">method=</span><span class="s">'post'</span><span class="nt">></span>
</code></pre></div><div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Change <code>basic_form.html</code> to submit via a post request.</li>
<li>Reload the page, fill in some new values and resubmit the form.</li>
<li>What happens? Have a look in the ‘Network’ section of developer tools.</li>
</ol>
</div>
<p>You should notice that this time <strong>the URL doesn’t change</strong>. When a form is submitted with a <code>POST</code> method the parameters are packaged up and sent along in the <code>headers</code>, instead of being put in the url. You can check this out in Developer tools:</p>
<p><img alt="dev tools form submit post" src="./Web Fundamentals 5_files/dev_tools_form_submit_post.png"></p>
<p>You can see the name and values have been packaged into a payload.</p>
<p><img alt="form submit payload" src="./Web Fundamentals 5_files/dev_tools_post_payload.png"></p>
<p><strong>Warning:</strong> Just because POST parameters aren’t sent in the URL <strong>doesn’t</strong> mean they are private. Unless you are using https, anyone watching your traffic can read all the information you’re submitting.</p>
<h3 id="submitting_to_a_different_url">Submitting to a different url</h3>
<p>So far all our requests have been to the URL we were on. On the whole, this isn’t too useful. It’s easy to change though:</p>
<div class="highlight"><pre><code class="html"> <span class="nt"><form</span> <span class="na">method=</span><span class="s">'post'</span> <span class="na">action=</span><span class="s">'thanks.html'</span><span class="nt">></span>
</code></pre></div>
<p>By setting the <code>action</code> attribute of the <code>form</code> tag we specify the URL to submit the form to.</p>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Set the form in <code>basic_form.html</code> to submit to <code>thanks.html</code>.</li>
<li>Refresh and resubmit the form.</li>
<li>What happens? Where has your data gone?</li>
</ol>
</div>
</div>
<div class="tab-pane" id="3_google_forms">
<h2>Google forms trick</h2>
<p>In order to have a working form on a website there needs to be somewhere for the information to go when the user clicks submit. So far we have only looked at <em>static</em> webpages: we have a dumb server that just hands out our hand-created HTML and CSS files. We have no way of accepting information from the user.</p>
<p>Later in the course we will build <em>dynamic</em> sites, using Ruby on Rails. In a <em>dynamic</em> site the server builds the pages depending on information stored in a database and details provided by the user. When we have a dynamic site we will just submit the form information back to the server.</p>
<p>In the meantime we will use a trick to submit the data from our form to a Google spreadsheet. We’ll be using our server (GitHub pages) to provide the form, but Google’s servers (for their spreadsheet) to collect the information. We’ll be roughly following the instructions from the <a href="http://morning.am/tutorials/how-to-style-google-forms/">morning.am google form post</a>. You might want to read this through first!</p>
<h3 id="setting_up_a_google_form">Setting up a Google form</h3>
<p>To set up a Google form you need a Google drive account. When you have one:</p>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Log in to Google drive.</li>
<li>Create a form. <img alt="Create Google form." src="./Web Fundamentals 5_files/google_drive_create_form.png"></li>
<li>Add a few text fields (e.g. name, email) to your form. <img alt="Google form add fields" src="./Web Fundamentals 5_files/google_form_add_questions.png"></li>
<li>Go to view the live form. <img alt="View live form" src="./Web Fundamentals 5_files/google_form_view_live.png"></li>
<li>Inspect the page source. Find the bit relating to the form.</li>
</ol>
</div>
<p>The bit of source relating to the form should look something like this:</p>
<div class="highlight"><pre><code class="html"><span class="nt"><form</span> <span class="na">action=</span><span class="s">"https://docs.google.com/forms/d/16faBBpyeqEBbHDyhM2K6s0i6UXBckz9vOQGwKrJKyN0/formResponse"</span> <span class="na">method=</span><span class="s">"POST"</span> <span class="na">id=</span><span class="s">"ss-form"</span> <span class="na">target=</span><span class="s">"_self"</span> <span class="na">onsubmit=</span><span class="s">""</span><span class="nt">></span>
<span class="nt"><ol</span> <span class="na">style=</span><span class="s">"padding-left: 0"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-form-question errorbox-good"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">dir=</span><span class="s">"ltr"</span> <span class="na">class=</span><span class="s">"ss-item ss-text"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-form-entry"</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">class=</span><span class="s">"ss-q-item-label"</span> <span class="na">for=</span><span class="s">"entry_1087713693"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-q-title"</span><span class="nt">></span>Name<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-q-help ss-secondary-text"</span> <span class="na">dir=</span><span class="s">"ltr"</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></label></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">name=</span><span class="s">"entry.1087713693"</span> <span class="na">value=</span><span class="s">""</span> <span class="na">class=</span><span class="s">"ss-q-short"</span> <span class="na">id=</span><span class="s">"entry_1087713693"</span> <span class="na">dir=</span><span class="s">"auto"</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-form-question errorbox-good"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">dir=</span><span class="s">"ltr"</span> <span class="na">class=</span><span class="s">"ss-item ss-text"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-form-entry"</span><span class="nt">></span>
<span class="nt"><label</span> <span class="na">class=</span><span class="s">"ss-q-item-label"</span> <span class="na">for=</span><span class="s">"entry_1239878056"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-q-title"</span><span class="nt">></span>Email
<span class="nt"></div></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-q-help ss-secondary-text"</span> <span class="na">dir=</span><span class="s">"ltr"</span><span class="nt">></div></span>
<span class="nt"></label></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">name=</span><span class="s">"entry.1239878056"</span> <span class="na">value=</span><span class="s">""</span> <span class="na">class=</span><span class="s">"ss-q-short"</span> <span class="na">id=</span><span class="s">"entry_1239878056"</span> <span class="na">dir=</span><span class="s">"auto"</span><span class="nt">></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"hidden"</span> <span class="na">name=</span><span class="s">"draftResponse"</span> <span class="na">value=</span><span class="s">"[]"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"hidden"</span> <span class="na">name=</span><span class="s">"pageHistory"</span> <span class="na">value=</span><span class="s">"0"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-item ss-navigate"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-form-entry"</span> <span class="na">id=</span><span class="s">"navigation-buttons"</span> <span class="na">dir=</span><span class="s">"ltr"</span> <span class="na">style=</span><span class="s">"display: inline-block"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"submit"</span> <span class="na">name=</span><span class="s">"submit"</span> <span class="na">value=</span><span class="s">"Submit"</span> <span class="na">id=</span><span class="s">"ss-submit"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"ss-secondary-text"</span><span class="nt">></span>Never submit passwords through Google Forms.<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"></ol></span>
<span class="nt"></form></span>
</code></pre></div>
<h3 id="create_your_own_form">Create your own form</h3>
<p>You’re now going to take the important bits from the form that Google created and create your own form containing them. The important bits are:</p>
<ul>
<li>The form <code>action</code>.</li>
<li>The form <code>method</code> (which should be ‘POST’).</li>
<li>The <code>name</code>s (and <code>type</code>s) from each of the input elements.</li>
</ul>
<p>If we copy all of these we will end up submitting the same parameters to the same place and our responses will be recorded in the spreadsheet.</p>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<p>Create your own form using the ‘important bits’ of the Google form.</p>
</div>
<p>It should look something like this:</p>
<div class="highlight"><pre><code class="html"><span class="nt"><form</span> <span class="na">action=</span><span class="s">"https://docs.google.com/forms/d/16faBBpyeqEBbHDyhM2K6s0i6UXBckz9vOQGwKrJKyN0/formResponse"</span> <span class="na">method=</span><span class="s">"POST"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">name=</span><span class="s">"entry.1087713693"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">name=</span><span class="s">"entry.1239878056"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"submit"</span> <span class="na">name=</span><span class="s">"submit"</span> <span class="na">value=</span><span class="s">"Submit"</span><span class="nt">></span>
<span class="nt"></form></span>
</code></pre></div>
<p>When you submit this form from your browser, you should end up at the Google ‘form submitted’ screen and your response should be in the spreadsheet.</p>
<p><img alt="Google form response" src="./Web Fundamentals 5_files/google_form_response.png"></p>
<h3 id="redirecting_the_submission">Redirecting the submission</h3>
<p>It isn’t ideal that after the submission the user is sent to a Google ‘form submitted’ page. Fortunately it is possible to change this. Again, following the instructions from the <a href="http://morning.am/tutorials/how-to-style-google-forms/">morning.am google form post</a>:</p>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<p>Add the required iframe and javascript snippet to redirect your form after submission, from the <a href="http://morning.am/tutorials/how-to-style-google-forms/">morning.am google form post</a>.</p>
</div>
<p>It should be something like this:</p>
<div class="highlight"><pre><code class="html"><span class="nt"><script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">></span><span class="kd">var</span> <span class="nx">submitted</span><span class="o">=</span><span class="kc">false</span><span class="p">;</span><span class="nt"></script></span>
<span class="nt"><iframe</span> <span class="na">name=</span><span class="s">"hidden_iframe"</span> <span class="na">id=</span><span class="s">"hidden_iframe"</span> <span class="na">style=</span><span class="s">"display:none;"</span> <span class="na">onload=</span><span class="s">"if(submitted) {window.location='thanks.html';}"</span><span class="nt">></iframe></span>
<span class="nt"><form</span> <span class="na">action=</span><span class="s">"https://docs.google.com/forms/d/16faBBpyeqEBbHDyhM2K6s0i6UXBckz9vOQGwKrJKyN0/formResponse"</span> <span class="na">method=</span><span class="s">"POST"</span> <span class="na">target=</span><span class="s">"hidden_iframe"</span> <span class="na">onsubmit=</span><span class="s">"submitted=true;"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">name=</span><span class="s">"entry.1087713693"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">name=</span><span class="s">"entry.1239878056"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"submit"</span> <span class="na">name=</span><span class="s">"submit"</span> <span class="na">value=</span><span class="s">"Submit"</span><span class="nt">></span>
<span class="nt"></form></span>
</code></pre></div>
<p>Don’t worry about too much about how this works at this stage. When the user submits the form, they should now be sent to your <code>thanks.html</code> page.</p>
<h3 id="a_few_things_about_google_forms">A few things about Google forms</h3>
<p>Two things to know about Google forms:</p>
<ol>
<li>You need to check that your form is accepting responses. On Form > Responses make sure that ‘Accepting Responses’ is ticked.</li>
<li>You can set it up to notify you when someone fills in the form. On <em>the spreadsheet for</em> your form go to Tools > Notification Rules.</li>
</ol>
</div>
<div class="tab-pane" id="4_more_elements">
<h2>More form elements</h2>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Open <code>form_elements.html</code> in Sublime Text and in Chrome.</li>
<li>Refer to both as you read through this page.</li>
</ol>
</div>
<p>So far we have only looked at text field elements. As you’re probably aware from experience, there are many other options for html form fields. Here are some of the most common:</p>
<h3 id="textarea">Textarea</h3>
<div class="highlight"><pre><code class="html"><span class="nt"><textarea</span> <span class="na">name=</span><span class="s">'feedback'</span> <span class="na">rows=</span><span class="s">"3"</span><span class="nt">></textarea></span>
</code></pre></div>
<p>A textarea is like a text field, except is is expandable.</p>
<h3 id="password_field">Password field</h3>
<div class="highlight"><pre><code class="html"><span class="nt"><input</span> <span class="na">type=</span><span class="s">'password'</span> <span class="na">name=</span><span class="s">'user_password'</span><span class="nt">></span>
</code></pre></div>
<p>Password fields obscure your input as you type. They <strong>do not</strong> encrypt the value that was input - the password will be sent in plain text as a normal name-value pair in the payload. In particular, <strong>if you’re using http, anyone snooping on the line can read your password</strong>. If you want to be secure you have to use https.</p>
<h3 id="radio_buttons_and_checkboxes">Radio buttons and checkboxes</h3>
<div class="highlight"><pre><code class="html"><span class="c"><!-- radio buttons --></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'radio'</span> <span class="na">name=</span><span class="s">'laptop-type'</span> <span class="na">value=</span><span class="s">'windows'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'radio'</span> <span class="na">name=</span><span class="s">'laptop-type'</span> <span class="na">value=</span><span class="s">'mac'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'radio'</span> <span class="na">name=</span><span class="s">'laptop-type'</span> <span class="na">value=</span><span class="s">'linux'</span><span class="nt">></span>
<span class="c"><!-- checkboxes --></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'checkbox'</span> <span class="na">name=</span><span class="s">'languages-known'</span> <span class="na">value=</span><span class="s">'html'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'checkbox'</span> <span class="na">name=</span><span class="s">'languages-known'</span> <span class="na">value=</span><span class="s">'css'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'checkbox'</span> <span class="na">name=</span><span class="s">'languages-known'</span> <span class="na">value=</span><span class="s">'ruby'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'checkbox'</span> <span class="na">name=</span><span class="s">'languages-known'</span> <span class="na">value=</span><span class="s">'javascript'</span><span class="nt">></span>
</code></pre></div>
<p>Radio buttons and checkboxes are similar:</p>
<ul>
<li>You have multiple options linked by having the same name.</li>
<li>Each option has a <code>value</code> which will be used in the name-value pair.</li>
</ul>
<p>They are different in that:</p>
<ul>
<li>In a group of radio buttons only one can be selected.</li>
<li>In a group of checkboxes you can select zero, one or many.</li>
<li>If you select multiple checkboxes a name-value pair will be created for each one.</li>
</ul>
<h3 id="select_boxes">Select boxes</h3>
<div class="highlight"><pre><code class="html"><span class="nt"><select</span> <span class="na">name=</span><span class="s">'fruits'</span><span class="nt">></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">'banana'</span><span class="nt">></span>banana<span class="nt"></option></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">'apple'</span><span class="nt">></span>apple<span class="nt"></option></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">'pear'</span><span class="nt">></span>pear<span class="nt"></option></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">'tomato'</span><span class="nt">></span>tomato<span class="nt"></option></span>
<span class="nt"></select></span>
</code></pre></div>
<p>Select boxes provide a drop-down list of options. Note how the <code><select></code> contains the name and each <code><option></code> has a different <code>value</code>.</p>
<h3 id="other_options">Other options</h3>
<div class="highlight"><pre><code class="html"><span class="nt"><input</span> <span class="na">type=</span><span class="s">'color'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'date'</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">'time'</span><span class="nt">></span>
</code></pre></div>
<p>There are several other options for html input types. For a complete list see <a href="http://www.w3schools.com/tags/tag_input.asp">here</a>. I don’t know how well supported these ‘other’ types are across browsers - I think they’re probably new in <a href="http://www.html5rocks.com/en/">html5</a>. Probably worth testing in multiple browsers (or googling to find out which browsers support them) before you start relying on them!</p>
<p>For more information about styling forms have a look at the <a href="http://getbootstrap.com/css/#forms">Twitter Bootstrap forms section</a>.</p>
</div>
<div class="tab-pane" id="5_homework">
<h2>Homework</h2>
<h3 id="add_a_contact_form_to_your_personal_site">Add a form to your project site</h3>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<p>Add a form to collect information, like an email address, on your project website</p>
</div>
<h3 id="start_on_the_landing_page_project">Tell us about your site</h3>
<div class="exercise alert alert-info"><strong>
<p>Task:</p>
</strong>
<ol>
<li>Tell us about your first site by filling in <a href="https://docs.google.com/forms/d/1V8wA--rmXQ8KvPmpooLZEZPwl7Vp64-XRPlOea9rRlU/viewform">this form</a>. If you’re still having problems getting it to display online or pointing your url to it, ask in the forum!</li>
</ol>
</div>
</div>
</div>
</div>
</div> <!-- /container -->
</body></html>