+ All Categories
Home > Technology > 13 html forms

13 html forms

Date post: 11-Nov-2014
Category:
Upload: rap-payne
View: 1,724 times
Download: 1 times
Share this document with a friend
Description:
 
Popular Tags:
31
HTML Forms … because a web session is a dialogue, not a monologue
Transcript
Page 1: 13 html forms

HTML Forms … because a web session is a dialogue, not a monologue

Page 2: 13 html forms

Forms are the main way to interact with the server

2. Server responds

with page 1

1. Browser requests page 1

3. Surfer fills out the form

fields and hits submit

4. Form data is sent in the

request header

5. Server processes

all that data

Page 3: 13 html forms

The <form> tag <form action="formAction.jsp" method="post">! What's your name? ! <input type="text" id="firstName" />! <br />! <input type="submit" />!</form>!

Page 4: 13 html forms

HTTP Methods GET

POST

PUT

DELETE

HEAD

TRACE

CONNECT

PATCH

OPTIONS

Page 5: 13 html forms

Forms post their data in the PUT request's header

Page 6: 13 html forms

What goes inside the form?

�  textarea ◦  for multiline text

�  select ◦  for dropdown lists and listboxes

�  input ◦  for text fields ◦  for checkboxes ◦  for radio buttons ◦  for file uploads

Page 7: 13 html forms

What else goes in the form?

" datalist – Creates a collection of data

" keygen – Generates an ad-hoc public/private key pair

" output ◦  Displays the results of a calculation

" progress – Shows the progress of a running task

" meter ◦  A measurement within a known range

Page 8: 13 html forms

textarea is for multiline text in forms <textarea> Digg is a social news website. Prior to Digg v4, its cornerstone function consisted of letting people vote stories up or down, called digging and burying, respectively. Digg's popularity prompted the creation of copycat social networking sites with story submission and voting systems </textarea>

Page 9: 13 html forms

select can be listboxes or dropdowns

<select multiple="multiple"> <option>David at the Dentist</option> <option>Chocolate Rain</option> <option>Double Rainbow</option> <option>Numa Numa</option> </select>

<select> <option>David at the Dentist</option> <option>Chocolate Rain</option> <option>Double Rainbow</option> <option>Numa Numa</option> </select>

Page 10: 13 html forms

"   datalist

� Does not appear to the user <label>Your favorite fruit:!<input type="text" name="fruit" list="fruits">!

<datalist id="fruits">! <option value="1">Blackberry</option>!

<option value="2">Blackcurrant</option>! <option value="3">Blueberry</option>! <!-- … -->!

</datalist>!</label>!

Page 11: 13 html forms

"   progress <p>Progress: <progress> <span id="p">0</span>% </progress> </p>!

<script>!

var progressBar = document.getElementById('p');!

function updateProgress(newValue) {!

progressBar.textContent = newValue;!

}!

</script>!

Page 12: 13 html forms

"   meter draws a gauge on the form Your score is: <meter>2 out of 10</meter>!

Page 13: 13 html forms

"   output creates a read-only result of a calculation

<form> <label for="nunchuk">Nunchuk Skillz: </label> <input id="nunchuk" ! type="range"! min="0" max="100"> <output for="nunchuk" ! onforminput = ! "value=nunchuk.valueAsNumber">! 0! </output> </form> !

Page 14: 13 html forms

inputs are for everything else

�  text � password �  checkbox �  radio �  file �  submit � button � hidden

"   email " url "   number "   range "   date " datetime " datetime-local "   month "   week "   time "   search "   color

Page 15: 13 html forms

The simple input types

�  text – for text (duh) � password – text, but the characters are not

typed back to the screen �  checkbox – has a boolean selected value �  radio – a radio button – like a checkbox

except that only one can be selected at a time �  submit – the button that submits the form

Page 16: 13 html forms

"   Requiring values

� Add required="required" to any form element <input id="email" type="email" required="required" />

Page 17: 13 html forms

demo: required form fields Hands-on required form fields

Page 18: 13 html forms

input type="file"

Allows the user to point to a file, usually for upload to the server

Page 19: 13 html forms

input type="button"

� A button that does nothing � You have to wire it up using JavaScript

Page 20: 13 html forms

input type="hidden"

The user never sees it, nor changes it Used to pass values between pages

Page 21: 13 html forms

"   input type="email"

� A text field, but only accepts values that look like email addresses

�  Show success and failed inputs

Page 22: 13 html forms

"   input type="url"

Same as email but with URLs

Page 23: 13 html forms

demo: email and url Hands-on email and url

Page 24: 13 html forms

"   <input type="date">

Page 25: 13 html forms

Other time-types

" time – the time of day only " datetime – a date and time combination

normalized around UTC (GMT) " datetime-local – same, but using the local

timezone " month – same as date but only month and year " week – a week number and year

Page 26: 13 html forms

"   input type="search"

� Looks nearly identical to text � More of a semantic difference

Page 27: 13 html forms

"   input type="color"

� A color picker � Returns a hex RGB number

Page 28: 13 html forms

demo: search and color Hands-on search and color

Page 29: 13 html forms

Whew! That's a lot of inputs

Page 30: 13 html forms

Conclusion

�  Forms are used to collect data from the user and then send them to the server for processing

� There are a few fields like textarea, select, datalist, keygen

� And there are lots on input fields with types of text, submit, search, time, color, number, range, url, and email

Page 31: 13 html forms

Further study


Recommended