Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an...

25
Introduction to Forms and HTML5 Controls Lecture 5

Transcript of Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an...

Page 1: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Introduction to Forms

and HTML5 Controls

Lecture 5

Page 2: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Outline

▰ Web Forms..

▰ Creating an HTML Form..

▰ Web Form Control..

2

Page 3: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

▰ Forms provide the user with an alternative way to interact with a web server.

▰ Web forms are present on virtually every website to you have ever visited:

search engine site, social media sites, e-commerce sites, college and

university website and many more.

▰ One particular type of web form that is found on every large web site is

search form or search bar.

3

Web Forms

Page 4: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

▰ Web form is created with a HTML element that contain objects called form

control

▰ Web page can have multiple form, but a form cannot be nested within

another form.

▰ Each form in the page is a separate entity.

4

Web Forms

Page 5: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

▰ A HTML form created with the <form> and </form> element.

▰ The form contains form controls witch users can:

➢ Enter data.

➢ Make selection from list

➢ Click radio button.

➢ Enter text in a text area box.

5

HTML Forms

Page 6: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

<FORM> element

▰ Two essential features of any form, namely the action

and the method attributes.

▰ The action attribute specifies the URL of the server-

side resource that will process the form data

▰ The method attribute specifies how the query string

data will be transmitted from the browser to the server.

6

Page 7: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

GET vs POST (methods)

7

Page 8: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

GET vs POST

GET

▰ Data can be clearly seen in the address bar.

▰ Data remains in browser history and cache.

▰ Data can be bookmarked

▰ Limit on the number of characters in the form data returned.

POST

▰ Data can contain binary data.

▰ Data is hidden from user.

▰ Submitted data is not stored in cache, history, or bookmarks.

8

Page 9: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Example

9

<!DOCTYPE html>

<html>

<body>

<h2>Text Input</h2>

<form>

First name:<br>

<input type="text" name="firstname">

<br>

Last name:<br>

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

</form>

<p>Note that the default width of a text input field is 20

characters.</p>

</body>

</html>

Page 10: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Web Form Control

Page 11: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

▰ Web form are not used just for performing a search; they are often used to collect visitor

information.

11

Type of Web Form Controls

Page 12: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Example for input text and Submit, Reset Buttons

12

<!DOCTYPE html>

<html>

<body>

<h2>HTML Forms</h2>

<form action="/action_page.php">

First name:<br>

<input type="text" name="firstname" value="Mickey">

<br>

Last name:<br>

<input type="text" name="lastname" value="Mouse">

<br><br>

<input type="submit" value="Submit">

<input type="reset">

</form>

<p>If you click the "Submit" button, the form-data will be sent to a page

called "/action_page.php".</p>

</body>

</html>

Page 13: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Example for Radio Button Input

13

<!DOCTYPE html>

<html>

<body>

<h2>Radio Buttons</h2>

<form>

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

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

<input type="radio" name="gender" value="other"> Other

</form>

</body>

</html>

Page 14: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

14

<!DOCTYPE html>

<html>

<head>

<title>Select Box Control</title>

</head>

<body>

Live Demo

<form>

<select name = "dropdown">

<option value = "Maths" >Maths</option>

<option value = "Physics“ selected >Physics</option>

</select>

</form>

</body>

</html>

Example for Select List Input

Page 15: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

15

<!DOCTYPE html>

<html>

<head>

<title>File Upload Box</title>

</head>

<body>

Live Demo

<form>

<input type = "file" name = "fileupload" accept = "image/*">

</form>

</body>

</html>

Example for File Upload Input

Page 16: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

Example for fieldset

16

<!DOCTYPE html>

<html>

<body>

<h2>Grouping Form Data with Fieldset</h2>

<p>The fieldset element is used to group related data in a

form, and the legend element defines a caption for the fieldset

element.</p>

<form action="/action_page.php">

<fieldset>

<legend>Personal information:</legend>

First name:<br>

<input type="text" name="firstname"

value="Mickey">

<br>

Last name:<br>

<input type="text" name="lastname"

value="Mouse">

<br><br>

<input type="submit“ value="Submit">

</fieldset>

</form>

</body>

</html>

Page 17: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

17

Example for fieldset

Page 18: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

HTML5 Controls

▰ The controls attribute is new in HTML5.

▰ This attribute is specifically intended for HTML5 <audio> and <video>

elements.

▰ The HTML5 controls attribute when used on either <audio> or <video>

element, it adds few controls on the browser. The controls added are

play/pause, volume , seeking and mute/ unmute. A full screen button

will be added for video and CC, track buttons if the author provides.

18

Page 19: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

19

<!DOCTYPE html>

<html>

<body>

<video width="320" height="240" controls>

<source src="movie.mp4" type="video/mp4">

<source src="movie.ogg" type="video/ogg">

Your browser does not support the video tag.

</video>

<p><strong>Note:</strong> The video tag is not supported in

Internet Explorer 8 and earlier versions.</p>

</body>

</html>

Example for A <video> element

Page 20: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

20

How it Works?

▰ The controls attribute adds video controls, like play, pause, and

volume.

▰ The <source> element allows you to specify alternative video files

which the browser may choose from.

▰ The browser will use the first recognized format.

▰ The text between the <video> and </video> tags will only be displayed

in browsers that do not support the <video> element.

Page 21: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

21

Example for A <video> element

Page 22: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

22

<!DOCTYPE html>

<html>

<body>

<video width="320" height="240" autoplay>

<source src="movie.mp4" type="video/mp4">

<source src="movie.ogg" type="video/ogg">

Your browser does not support the video tag.

</video>

<p><strong>Note:</strong> The video tag is not supported in

Internet Explorer 8 and earlier versions.</p>

</body>

</html>

Example for A <video> element with

autoplay

Page 23: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

23

Example for A <video> element with

autoplay

Page 24: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

24

<!DOCTYPE html>

<html>

<body>

<audio controls>

<source src="horse.ogg" type="audio/ogg">

<source src="horse.mp3" type="audio/mpeg">

Your browser does not support the audio element.

</audio>

</body>

</html>

Example for A <Audio> element

Page 25: Introduction to Forms and HTML5 Controls · 2020-02-25 · Forms provide the user with an alternative way to interact with a web server. Web forms are present on virtually every website

25

How it Works?

▰ The <source> element allows you to specify alternative audio files

which the browser may choose from.

▰ The browser will use the first recognized format.

▰ The text between the <audio> and </audio> tags will only be displayed

in browsers that do not support the <audio> element.