+ All Categories
Home > Documents > WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML...

WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML...

Date post: 25-Dec-2015
Category:
Upload: lionel-goodwin
View: 221 times
Download: 3 times
Share this document with a friend
Popular Tags:
35
WEB FORMS ART340
Transcript
Page 1: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

WEB FORMSART340

Page 2: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible to collect information from visitors.

What are some different types of forms?

WHAT IS AN HTML FORM?

Page 3: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Examples

Making a Purchase Signing up for a Mailing List Requesting Product

Information Contact Form Donation Form Search Boxes Online Shopping Interfaces

Page 4: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

How Forms Work

1. Browser reads your markup and renders form control elements on page.

2. Users enter info into fields and click

3. Browser collects info and encodes it.

4. Browsers sends it to the processor on the server.

5. Processor accepts info and processes it (however it was written to do so).

6. The web application returns a response and sends it back to the browser where it is displayed.

Simply, data is entered, collected, processed, and then a response is displayed.

Submit

Page 5: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Form ComponentsThe Form Controls:

The visual: Buttons, Text Fields,

Checkboxes, etc.

The Processor:Make it work: An

application or script that processes the info

collected by the form, and returns a response.

Page 6: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The Steps of a Transaction

Page 7: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The <form> Tag

<form>Where the magic happens.</form>

A container for all form content. May also contain block-level elements (<p>). May not contain another form. In order for the form to actually do something,

attributes, such as action and method, must be set.

Page 8: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The action attribute

Describes the processing page, location (URL) of the application or script.

In the text, you used a .php page to process. PHP is an open source scripting language most

commonly used with the Apache Web Server. Most of the time, you will work with a web

developer or server administrator who will provide the name and location of the program.

Page 9: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The method attribute

Specifies how the info should be sent to the server. Two methods:

POST – Send a separate server request. Only server sees data. Good for private info. No character limit.

GET – Encoded data gets added to the URL sent to the server. Good for bookmarking form data, such as search results. Not good for private information. 256 character limit.

Page 10: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

A form element, or control, allows users to enter info or choose options. (entry fields, buttons, menus, etc.)

FORM CONTROLS

Page 11: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Controls for Adding Text

Text Input: Single line of text (i.e.. email, name)

Password Input: Single line of masked text

Textarea: Multi-line of text (i.e.. messages, comments)

Page 12: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Text Input

First name: <input type="text“ name="firstname"> <br>Last name: <input type="text" name="lastname">

First name: <input type="text“ name="firstname"> <br>

Last name: <input type="text" name="lastname">

The <input> element is used for several different

form controls.

When the type

attribute has a value of “text” it creates a single line text input.

The name attribute tells

the server the name of the data.

Page 13: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Password Input

First name: <input type="text“ name="firstname"> <br>Last name: <input type="text" name="lastname">

Password: <input type="password" name="pwd">

The <input> element is used for several

different form controls.

When the type attribute has a

value of “password” it

creates a single line text

input that it masks.

The name attribute tells the server the name of the

data.

Page 14: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Textarea

<textarea name=“comments”> Enter your comment. </textarea>

The <textarea> element creates a multi-line

text input.

Any text in between,

will appear in the text box to the

user.

The name attribute tells the

server the name of the

data.

Page 15: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Controls for Making Choices

Radio buttons: One selection must be made.

Checkboxes: Multiple selections can be made.

Drop-down boxes: One selection must be made from a list.

Page 16: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Radio Buttons

First name: <input type="text“ name="firstname"> <br>Last name: <input type="text" name="lastname">

<input type="radio" name=“gender" value="male">Male<br>

<input type="radio" name=“gender" value="female">Female

The <input> element is used for several different

form controls.

When the type

attribute has a value of “radio” it creates a radio button

for one selection.

The name attribute tells the

server the name of the data. Same

for all buttons.

The value attribute indicates

the selected option.

Page 17: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Checkboxes

First name: <input type="text“ name="firstname"> <br>Last name: <input type="text" name="lastname">

<input type="checkbox" name="vehicle" value=“bike">I have a bike<br>

<input type="checkbox" name="vehicle" value=“car">I have a car 

The <input> element is used for several different

form controls.

When the type

attribute has a value

of “checkbox” it creates

a button that allows

multiple selections.

The name attribute tells the

server the name of the data. Same

for all buttons.

When checked, the value attribute indicates

the selected option.

Page 18: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Drop-down Boxes

<select name=“cars”><option value="volvo">Volvo</option>

<option value="saab">Saab</option><option value="opel">Opel</option>

<option value="audi">Audi</option></select>The

<select>

element is used

to create a

drop-down

list box.

The name

attribute tells the server

the name of

the data.

The <option

> element indicate

s the options the user

can select from.

The value

attribute indicate

s the selected option.

Page 19: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Controls for Submitting

Submit button: Submits data from your form to another page on the server.

Image button: Same as above, but replaces button with an image.

Submit

Page 20: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Submit Button

First name: <input type="text“ name="firstname"> <br>Last name: <input type="text" name="lastname">

<form name="input" action="html_form_action.asp" method="get">

Username: <input type="text" name="user"><input type="submit" value="Submit"></form>

When the type

attribute has a value of

“submit”, it is used to

send a form to the server.

The name attribute can be used, but

is not necessary.

The value attribute is

used to control the text that

appears on the button.

Page 21: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Image Button

First name: <input type="text“ name="firstname"> <br>Last name: <input type="text" name="lastname">

<form name="input" action="html_form_action.asp" method="get">

Username: <input type="text" name="user"><input type=“image" src=“images.jpg” width=“100”

height=“20”></form>When the

type attribute has

a value of “image” it

allows you to use an image for the submit

button.

The name attribute can be used, but

is not necessary.

The src, width,

height, and alt, attributes

work the same as the

<img> element.

Submit

Page 22: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

LABELING FORM CONTROLS

Page 23: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Why Use Labels?

Labels identify the purpose of each form control. By using labels,

the form is accessible to the visually impaired.

Some labels we will use include: <label> <fieldset> <legend>

Page 24: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The <label> Tag

Labels a form control. One per form control. Two ways to use:

Nested: Label wraps around the text description and the form control.

Separate (for): Label kept separate. Uses “for” attribute to indicate which form control it is labeling.

Page 25: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Nested vs. Separate

Nested: Label wraps around the text description and the form control.

Separate (for): Label kept separate. Uses “for” attribute to indicate which form control it is labeling.

<label> Age: <input type=“text” name=“age” /></label>

<label for=”year”> Age: </label><input type=“text” name=“age” id=“year" />

Page 26: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The <fieldset> Tag

Groups form elements together. Helpful with longer forms. Most browsers show a line around the edge of the

fieldset. Can be adjusted using CSS.

<fieldset>Wraps around grouped form elements.</fieldset>

Page 27: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

The <legend> Tag

Comes directly after the opening of the <fieldset> tag. Contains a caption which identifies the purposes of

that control group.

<fieldset><legend>My Radio buttons</legend></fieldset>

Page 28: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

SENDING INFORMATION

Page 29: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Name/Value

If forms collect data, how is it sent to the server?

All information is sent in name/value pairs. The name attribute names the control. Data entered/selected by the user, is the value. All form control elements (except Submit and Reset)

must include a name so that the form processor can sort the info.

Tip: You should never change the name of a form control unless you are certain the server code will understand it.

Page 30: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Name/Value Example

In this example, the name is “comment” and the value is “Would you like to comment?”:

<textarea name =“comment”>Would you like to comment?</textarea>

Page 31: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Spry Form Validation

Form validation ensures that users have filled in the form control correctly.

Messages can be provided to users to assist them in filling out the necessary content.

Page 32: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Browser Defaults

Page 33: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Simple Contact Form HTML

Place on page and modify as needed:

<form action="mail.php" method="post">      <fieldset>      <legend>Contact</legend>      <p><label for="name">Name: </label>      <input type="text" name="name" id="name" /></p>      <p><label for="email">Email:</label>      <input type="text" name="email" id="email" /></p>      <p><label for="comments">Comments:</label><br />      <textarea id="comments" name="message" cols="" rows="">Enter your comments...</textarea></p>      <p><input type="submit" value="Submit"/></p>      </fieldset>    </form>

Page 34: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

Simple Contact Form PHP

Create mail.php and copy and paste the following PHP before the <DOCTYPE>:

Name: "mail.php"<?php $name = $_POST['name'];$email = $_POST['email'];$message = $_POST['message'];$formcontent="From: $name \n Message: $message";$recipient = "[email protected]";$subject = "Contact Form";$mailheader = "From: $email \r\n";mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");echo "Thank You!";?>

Page 35: WEB FORMS ART340. On the web, a form makes it possible for users to pass data to a server. HTML forms provides a set of controls that make it possible.

References

Duckett, Jon. HTML & CSS: Design and Build Websites. Indianapolis, IN : Chichester: Wiley, 2011. Print.

“HTML Forms and Input.“ W3CSchools.com. Web. 24 Nov 2012.<http://www.w3schools.com/html/html_forms.asp>.

Niederst Robbins, Jennifer. Learning Web Design: A Beginner's Guide to (X)HTML, Style Sheets and Web Graphics. 3rd ed. Beijing ; Sebastopol, CA: O'Reilly, 2007. Print.


Recommended