html foundations, pt 3: forms

49
FORMS 22-3375 Web Design I

Upload: shawn-calvert

Post on 28-Jan-2015

116 views

Category:

Design


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: HTML Foundations, pt 3: Forms

FORMS 22-3375 Web Design I

Page 2: HTML Foundations, pt 3: Forms

Student Presentations

Present your initial ideas for your portfolio

Walk us through the !ow (homepage, detail, about)

What types of work will you be showing?

Page 3: HTML Foundations, pt 3: Forms
Page 4: HTML Foundations, pt 3: Forms

What is a form?Forms provide an interface allowing users to interact in some way with your site.

Forms collect input via controls, such as buttons, text "elds, or scrolling menus. Controls are placed on the page using special elements in the markup. These elements are merely an interface for collecting information and do not actually possess the data.

from Web Design in a Nutshell by Jennifer Niederst Robbins

Page 5: HTML Foundations, pt 3: Forms
Page 6: HTML Foundations, pt 3: Forms
Page 7: HTML Foundations, pt 3: Forms

Form Types

Page 8: HTML Foundations, pt 3: Forms

There are three basic types of form controls, for:

Adding Text

Making Choices

Submitting Forms

Uploading Files

Page 9: HTML Foundations, pt 3: Forms

Adding Text

Text Input

Password Input

Text Area

Page 10: HTML Foundations, pt 3: Forms

Making Choices

Radio Buttons

Checkboxes

Drop-downs

Page 11: HTML Foundations, pt 3: Forms

Submitting Forms

Submit Buttons

Image Buttons

Buttons

Page 12: HTML Foundations, pt 3: Forms

Uploading Files

File Upload

Page 13: HTML Foundations, pt 3: Forms

Form Syntax

Page 14: HTML Foundations, pt 3: Forms

The <form> tag is used to create an HTML form for user input.

<form></form>

Page 15: HTML Foundations, pt 3: Forms

<input> elements are used within a <form> element to declare input controls that allow users to input data.

<input> is an inline, self-closing tag.

An input "eld can vary in many ways, depending on the type attribute.

<form> <input>

</form>

Page 16: HTML Foundations, pt 3: Forms

The <input> tag should always have, at a minimum, a type and name attribute.

The “type” attribute controls the form type (text, radio, dropdown, etc), and the “name” attribute is how you identify the data when it is sent to the server.

<form>

<input type=”text” name=”username”>

</form>

Page 17: HTML Foundations, pt 3: Forms

Input Attributes: type

You create the different type of form elements through the “type” attribute.

These include: text, password, radio, checkbox, select, !le, submit, image, and hidden.

Page 18: HTML Foundations, pt 3: Forms

Input Attributes: type

For example:

<input type=”text”>

would create this:

Page 19: HTML Foundations, pt 3: Forms

Input Attributes: name

You then need to add a name so the data can be identi"ed by the server:

<input type=”text” name=”username”>

Page 20: HTML Foundations, pt 3: Forms

Class Exercise

Create a form for our tutorial:

Text input (name)

Dropdown (favorite color)

Radio (human or robot)

Text area (comment)

Submit

Page 21: HTML Foundations, pt 3: Forms

Adding Text: Examples

Text Input

Page 22: HTML Foundations, pt 3: Forms

Adding Text: Examples

Text Input You can add additional attributes to your text inputs to control their width (size, in characters), and maxlength (in characthers). You can also control the width of the input "eld in your css (in pixels, % or ems).

Page 23: HTML Foundations, pt 3: Forms

Adding Text: Examples

Text Area Text areas are a bit different: they are not contained in an <input> tag, and they require a closing tag (<textarea></textarea>.

Page 24: HTML Foundations, pt 3: Forms

Making Choices: Checkboxes

Checkboxes With checkboxes and radio buttons, the “name” attribute creates the grouping between the options. The “value” attribute tells the server which option the user selected. add a “checked” value if you want an option to be preselected.

Page 25: HTML Foundations, pt 3: Forms

Making Choices: Radio Buttons

Radio Buttons Use a radio button when the user can only select one option. Like checkboxes, add a “checked” value if you want an option to be preselected.

Page 26: HTML Foundations, pt 3: Forms

Making Choices: Dropdowns

Drop-downs Dropdowns are made up of two opening and closing tags: <select> and <option>. Whatever option appears at the top is the default, unless you add a “selected=”selected” attribute to the option tag.

Page 27: HTML Foundations, pt 3: Forms

Uploading Files

File Upload

Page 28: HTML Foundations, pt 3: Forms

Submitting Forms: Submit

Submit A simple <input type=”submit”> is the easiest way to add a submit button to your form. You can hook onto this element in css by using the pseudo selector input[type=submit].

Page 29: HTML Foundations, pt 3: Forms

Submitting Forms: Image

Image <input type=”image”> allows you to replace the standard submit button with an image of a submit button. This method is not recommended.

Page 30: HTML Foundations, pt 3: Forms

Submitting Forms: Button

Button Inside a <button> element you can put content, like text or images. This is the difference between this element and buttons created with the <input> element.

Page 31: HTML Foundations, pt 3: Forms

EXAMPLE

Page 32: HTML Foundations, pt 3: Forms

Form Labels

Page 33: HTML Foundations, pt 3: Forms

There are a few ways to add labels to your form elements. The simplest way is to just add unmarked up text with <br> elements.

<form>

Your Name<br><input type=”text” name=”name”><br>

Your Email<br><input type=”text” name=”email”><br>

<input type=”submit”>

</form>

Page 34: HTML Foundations, pt 3: Forms

Another way is to use the “label” element. It can wrap both the label and input, or stand outside of the input. You can style the label element in css.

If you use this method, you should add a “for” attribute to the label that matches the id of the form element (not required, but good for accessibility reasons).

<label for=”name”> Your Name<label><br>

<input type=”text” name=”name” id=”name”>

Page 35: HTML Foundations, pt 3: Forms

You can also wrap the entire element in the label tag. Both used of the label tag give your radio and checkboxes the added feature of making the entire "eld clickable.

<label>

Your Name<br><input type=”text” name=”name”>

<label>

Page 36: HTML Foundations, pt 3: Forms

Form Design

Page 37: HTML Foundations, pt 3: Forms
Page 38: HTML Foundations, pt 3: Forms
Page 39: HTML Foundations, pt 3: Forms
Page 40: HTML Foundations, pt 3: Forms
Page 41: HTML Foundations, pt 3: Forms
Page 42: HTML Foundations, pt 3: Forms
Page 43: HTML Foundations, pt 3: Forms
Page 44: HTML Foundations, pt 3: Forms
Page 45: HTML Foundations, pt 3: Forms
Page 46: HTML Foundations, pt 3: Forms
Page 47: HTML Foundations, pt 3: Forms
Page 48: HTML Foundations, pt 3: Forms
Page 49: HTML Foundations, pt 3: Forms