HTML Foundations, pt 3: Forms

Post on 28-Jan-2015

117 views 2 download

Tags:

description

 

Transcript of HTML Foundations, pt 3: Forms

FORMS 22-3375 Web Design I

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?

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

Form Types

There are three basic types of form controls, for:

Adding Text

Making Choices

Submitting Forms

Uploading Files

Adding Text

Text Input

Password Input

Text Area

Making Choices

Radio Buttons

Checkboxes

Drop-downs

Submitting Forms

Submit Buttons

Image Buttons

Buttons

Uploading Files

File Upload

Form Syntax

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

<form></form>

<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>

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>

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.

Input Attributes: type

For example:

<input type=”text”>

would create this:

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”>

Class Exercise

Create a form for our tutorial:

Text input (name)

Dropdown (favorite color)

Radio (human or robot)

Text area (comment)

Submit

Adding Text: Examples

Text Input

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).

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>.

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.

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.

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.

Uploading Files

File Upload

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].

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.

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.

EXAMPLE

Form Labels

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>

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”>

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>

Form Design