SlideShare a Scribd company logo
WEB DEVELOPMENT
HTML Forms
Learning Outcomes:
Upon completion of this lesson, students should be able to;
 Create forms with basic elements such as text boxes and buttons:
 Create forms using HTML5 elements such as form validation and email address fields.
HTML Forms
 Although forms could simply be used to display information, HTML provides them in order to
supply a way for the user to interact with a Web server.
 The most widely used method to process the data submitted through a form is to send it to server-
side software typically written in a scripting language, although any programming language can
be used.
 Typically, form data is sent to a server (or to an email address) as a sequence of pairs, each pair
being made up of a name and an associated value.
 The method that this data uses to arrive at its destination depends on the data encoding.
HTML Forms
An HTML form is used to collect user input. The user input is most often sent to a server for
processing.
The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>
HTML Form Elements
The HTML <form> element can contain one or more of the following form elements:
<input>
<label>
<select>
<textarea>
<button>
<fieldset>
<legend>
<datalist>
<output>
<option>
<optgroup>
HTML Input Types
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
The <input> Element
The HTML <input> element is the most used form element.
An <input> element can be displayed in many ways, depending on the type attribute.
A form with input fields for text:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
Radio Buttons
The <input type="radio"> defines a radio button.
Radio buttons let a user select ONE of a limited number of choices.
A form with radio buttons:
<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
</form>
Checkboxes
The <input type="checkbox"> defines a checkbox.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
A form with checkboxes:
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
The Submit Button
The <input type="checkbox"> defines a checkbox.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
The <input type="submit"> defines a button for submitting the form data to a form-handler.
The form-handler is typically a file on the server with a script for processing input data.
The form-handler is specified in the form's action attribute
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Input Type Password
<input type="password"> defines a password field:
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
Input Type Reset
<input type="reset"> defines a reset button that will reset all form values to their default values:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
Input Type Button
<input type="button"> defines a button:
<input type="button" onclick="alert('Hello World!')" value="Click Me!">
Input Type Color
The <input type="color"> is used for input fields that should contain a color.
Depending on browser support, a color picker can show up in the input field.
<form>
<label for="favcolor">Select your favorite color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>
Input Type Date
The <input type="date"> is used for input fields that should contain a date.
Depending on browser support, a date picker can show up in the input field.
<form>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
</form>
You can also use the min and max attributes to add restrictions to dates:
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-31"><br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-02">
</form>
Input Type Datetime-local
The <input type="datetime-local"> specifies a date and time input field, with no time zone.
Depending on browser support, a date picker can show up in the input field.
<form>
<label for="birthdaytime">Birthday (date and time):</label>
<input type="datetime-local" id="birthdaytime" name="birthdaytime">
</form>
Input Type Email
The <input type="email"> is used for input fields that should contain an e-mail address.
Depending on browser support, the e-mail address can be automatically validated when submitted.
Some smartphones recognize the email type, and add ".com" to the keyboard to match email input.
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>
Input Type File
The <input type="file"> defines a file-select field and a "Browse" button for file uploads.
<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>
Input Type Month
The <input type="month"> allows the user to select a month and year.
Depending on browser support, a date picker can show up in the input field.
<form>
<label for="bdaymonth">Birthday (month and year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>
Input Type Search
The <input type="search"> is used for search fields (a search field behaves like a
regular text field).
<form>
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
</form>
Input Type Tel
The <input type="tel"> is used for input fields that should contain a telephone
number.
<form>
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
</form>
The <label> Element
The <label> tag defines a label for many form elements.
The <label> element is useful for screen-reader users, because the screen-reader will read out loud
the label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very small regions (such as radio
buttons or checkboxes) - because when the user clicks the text within the <label> element, it
toggles the radio button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of the <input> element to
bind them together.
The <select> Element
The <select> element defines a drop-down list:
<label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
The <option> elements defines an option that can be selected.
By default, the first item in the drop-down list is selected.
To define a pre-selected option, add the selected attribute to the option:
The <select> Element
Allow Multiple Selections:
Use the multiple attribute to allow the user to select more than one value:
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="4" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
The <textarea> Element
The <textarea> element defines a multi-line input field (a text area):
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
The rows attribute specifies the visible number of lines in a text area.
The cols attribute specifies the visible width of a text area.
The <fieldset> and <legend> Elements
The <fieldset> element is used to group related data in a form.
The <legend> element defines a caption for the <fieldset> element.
<form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
The <datalist> Element
The <datalist> element specifies a list of pre-defined options for an <input> element.
Users will see a drop-down list of the pre-defined options as they input data.
The list attribute of the <input> element, must refer to the id attribute of the <datalist> element.
<form action="/action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
HTML Form Attributes
The Action Attribute
The action attribute defines the action to be performed when the form is submitted.
Usually, the form data is sent to a file on the server when the user clicks on the submit button.
In the example below, the form data is sent to a file called "action_page.php". This file contains a server-side
script that handles the form data:
On submit, send form data to "action_page.php":
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
If the action attribute is omitted, the action is set to the current page.
The Target Attribute
The target attribute specifies where to display the response that is received
after submitting the form.
The default value is _self which means that the response will open in the current
window.
Here, the submitted result will open in a new browser tab:
<form action="/action_page.php" target="_blank">
The Method Attribute
The method attribute specifies the HTTP method to be used when submitting the form data.
The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with
method="post").
The default HTTP method when submitting form data is GET.
This example uses the GET method when submitting the form data:
<form action="/action_page.php" method="get">
This example uses the POST method when submitting the form data:
<form action="/action_page.php" method="post">
Always use POST if the form data contains sensitive or personal information!
The Method Attribute
Appends the form data to the URL, in
name/value pairs
NEVER use GET to send sensitive data!
(the submitted form data is visible in the
URL!)
The length of a URL is limited (2048
characters)
Useful for form submissions where a user
wants to bookmark the result
GET is good for non-secure data, like
query strings in Google
Appends the form data inside the body
of the HTTP request (the submitted
form data is not shown in the URL)
POST has no size limitations, and can
be used to send large amounts of
data.
Form submissions with POST cannot be
bookmarked
The Autocomplete Attribute
The autocomplete attribute specifies whether a form should have autocomplete
on or off.
When autocomplete is on, the browser automatically complete values based on
values that the user has entered before.
A form with autocomplete on:
<form action="/action_page.php" autocomplete="on">
The Novalidate Attribute
The novalidate attribute is a boolean attribute.
When present, it specifies that the form-data (input) should not be validated
when submitted.
A form with a novalidate attribute:
<form action="/action_page.php" novalidate>
The Name Attribute for <input>
Notice that each input field must have a name attribute to be submitted.
If the name attribute is omitted, the value of the input field will not be sent at all.
This example will not submit the value of the "First name" input field:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" value="John"><br><br>
<input type="submit" value="Submit">
</form>
Q & A
THANK YOU

More Related Content

PPTX
Lecture-5.pptx
PPTX
unit2_HTML_Forms fundamentals of html and crore concepts.pptx
PPTX
Designing web pages html forms and input
PPTX
Lectures-web
PPTX
Html form tag
PPTX
HTML Forms Basics by Kamran Solangi.pptx
PPTX
HTML DAY 4 presentation for beginners friendly
PPTX
HTML Forms: The HTML element represents a document section containing interac...
Lecture-5.pptx
unit2_HTML_Forms fundamentals of html and crore concepts.pptx
Designing web pages html forms and input
Lectures-web
Html form tag
HTML Forms Basics by Kamran Solangi.pptx
HTML DAY 4 presentation for beginners friendly
HTML Forms: The HTML element represents a document section containing interac...

Similar to HTML FORMS.pptx (20)

DOCX
PPT
Forms,Frames.ppt
PPT
Forms,Frames.ppt
PPSX
Lecture-5.ppsx
PPT
HTML_Forms_.ppt
DOC
Html basics 10 form
 
PPTX
Web forms - Learn web development (1).pptx
DOCX
I211 – Information Infrastructure IILecture 20TodayCGI.docx
PPTX
Web topic 20 2 html forms
PPTX
Web topic 20 1 html forms
PPTX
lecture9-10-160807085530.pptx dgdg fdgdfv ds
PPTX
HYPERTEXT MARK UP LANGUAGES (HTML) FORMS
PDF
COMP-10-ONLINE-FORMS Powerpoint Presentation
PPTX
Higher - HTML forms
PPTX
HNDIT1022 Week 03 Part 2 Theory information.pptx
PPT
HtmlForms- basic HTML forms description.
ODP
HTML 5 Simple Tutorial Part 4
PPT
20-html-forms.ppt
PDF
CSS_Forms.pdf
Forms,Frames.ppt
Forms,Frames.ppt
Lecture-5.ppsx
HTML_Forms_.ppt
Html basics 10 form
 
Web forms - Learn web development (1).pptx
I211 – Information Infrastructure IILecture 20TodayCGI.docx
Web topic 20 2 html forms
Web topic 20 1 html forms
lecture9-10-160807085530.pptx dgdg fdgdfv ds
HYPERTEXT MARK UP LANGUAGES (HTML) FORMS
COMP-10-ONLINE-FORMS Powerpoint Presentation
Higher - HTML forms
HNDIT1022 Week 03 Part 2 Theory information.pptx
HtmlForms- basic HTML forms description.
HTML 5 Simple Tutorial Part 4
20-html-forms.ppt
CSS_Forms.pdf
Ad

Recently uploaded (20)

PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PPTX
Transform Your Business with a Software ERP System
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
assetexplorer- product-overview - presentation
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
history of c programming in notes for students .pptx
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Cost to Outsource Software Development in 2025
PDF
medical staffing services at VALiNTRY
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Nekopoi APK 2025 free lastest update
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Transform Your Business with a Software ERP System
Navsoft: AI-Powered Business Solutions & Custom Software Development
assetexplorer- product-overview - presentation
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Wondershare Filmora 15 Crack With Activation Key [2025
Odoo Companies in India – Driving Business Transformation.pdf
history of c programming in notes for students .pptx
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Digital Systems & Binary Numbers (comprehensive )
Autodesk AutoCAD Crack Free Download 2025
CHAPTER 2 - PM Management and IT Context
Cost to Outsource Software Development in 2025
medical staffing services at VALiNTRY
Patient Appointment Booking in Odoo with online payment
Nekopoi APK 2025 free lastest update
Complete Guide to Website Development in Malaysia for SMEs
How to Choose the Right IT Partner for Your Business in Malaysia
Ad

HTML FORMS.pptx

  • 2. Learning Outcomes: Upon completion of this lesson, students should be able to;  Create forms with basic elements such as text boxes and buttons:  Create forms using HTML5 elements such as form validation and email address fields.
  • 3. HTML Forms  Although forms could simply be used to display information, HTML provides them in order to supply a way for the user to interact with a Web server.  The most widely used method to process the data submitted through a form is to send it to server- side software typically written in a scripting language, although any programming language can be used.  Typically, form data is sent to a server (or to an email address) as a sequence of pairs, each pair being made up of a name and an associated value.  The method that this data uses to arrive at its destination depends on the data encoding.
  • 4. HTML Forms An HTML form is used to collect user input. The user input is most often sent to a server for processing. The HTML <form> element is used to create an HTML form for user input: <form> . form elements . </form>
  • 5. HTML Form Elements The HTML <form> element can contain one or more of the following form elements: <input> <label> <select> <textarea> <button> <fieldset> <legend> <datalist> <output> <option> <optgroup>
  • 6. HTML Input Types <input type="button"> <input type="checkbox"> <input type="color"> <input type="date"> <input type="datetime-local"> <input type="email"> <input type="file"> <input type="hidden"> <input type="image"> <input type="month"> <input type="number"> <input type="password"> <input type="radio"> <input type="range"> <input type="reset"> <input type="search"> <input type="submit"> <input type="tel"> <input type="text"> <input type="time"> <input type="url"> <input type="week">
  • 7. The <input> Element The HTML <input> element is the most used form element. An <input> element can be displayed in many ways, depending on the type attribute. A form with input fields for text: <form> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname"> </form>
  • 8. Radio Buttons The <input type="radio"> defines a radio button. Radio buttons let a user select ONE of a limited number of choices. A form with radio buttons: <form> <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label><br> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label><br> <input type="radio" id="other" name="gender" value="other"> <label for="other">Other</label> </form>
  • 9. Checkboxes The <input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number of choices. A form with checkboxes: <form> <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike"> <label for="vehicle1"> I have a bike</label><br> <input type="checkbox" id="vehicle2" name="vehicle2" value="Car"> <label for="vehicle2"> I have a car</label><br> <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat"> <label for="vehicle3"> I have a boat</label> </form>
  • 10. The Submit Button The <input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number of choices. The <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a file on the server with a script for processing input data. The form-handler is specified in the form's action attribute <form action="/action_page.php"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"><br><br> <input type="submit" value="Submit"> </form>
  • 11. Input Type Password <input type="password"> defines a password field: <form> <label for="username">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="pwd">Password:</label><br> <input type="password" id="pwd" name="pwd"> </form>
  • 12. Input Type Reset <input type="reset"> defines a reset button that will reset all form values to their default values: <form action="/action_page.php"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"><br><br> <input type="submit" value="Submit"> <input type="reset"> </form>
  • 13. Input Type Button <input type="button"> defines a button: <input type="button" onclick="alert('Hello World!')" value="Click Me!">
  • 14. Input Type Color The <input type="color"> is used for input fields that should contain a color. Depending on browser support, a color picker can show up in the input field. <form> <label for="favcolor">Select your favorite color:</label> <input type="color" id="favcolor" name="favcolor"> </form>
  • 15. Input Type Date The <input type="date"> is used for input fields that should contain a date. Depending on browser support, a date picker can show up in the input field. <form> <label for="birthday">Birthday:</label> <input type="date" id="birthday" name="birthday"> </form> You can also use the min and max attributes to add restrictions to dates: <form> <label for="datemax">Enter a date before 1980-01-01:</label> <input type="date" id="datemax" name="datemax" max="1979-12-31"><br><br> <label for="datemin">Enter a date after 2000-01-01:</label> <input type="date" id="datemin" name="datemin" min="2000-01-02"> </form>
  • 16. Input Type Datetime-local The <input type="datetime-local"> specifies a date and time input field, with no time zone. Depending on browser support, a date picker can show up in the input field. <form> <label for="birthdaytime">Birthday (date and time):</label> <input type="datetime-local" id="birthdaytime" name="birthdaytime"> </form>
  • 17. Input Type Email The <input type="email"> is used for input fields that should contain an e-mail address. Depending on browser support, the e-mail address can be automatically validated when submitted. Some smartphones recognize the email type, and add ".com" to the keyboard to match email input. <form> <label for="email">Enter your email:</label> <input type="email" id="email" name="email"> </form>
  • 18. Input Type File The <input type="file"> defines a file-select field and a "Browse" button for file uploads. <form> <label for="myfile">Select a file:</label> <input type="file" id="myfile" name="myfile"> </form>
  • 19. Input Type Month The <input type="month"> allows the user to select a month and year. Depending on browser support, a date picker can show up in the input field. <form> <label for="bdaymonth">Birthday (month and year):</label> <input type="month" id="bdaymonth" name="bdaymonth"> </form>
  • 20. Input Type Search The <input type="search"> is used for search fields (a search field behaves like a regular text field). <form> <label for="gsearch">Search Google:</label> <input type="search" id="gsearch" name="gsearch"> </form>
  • 21. Input Type Tel The <input type="tel"> is used for input fields that should contain a telephone number. <form> <label for="phone">Enter your phone number:</label> <input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}"> </form>
  • 22. The <label> Element The <label> tag defines a label for many form elements. The <label> element is useful for screen-reader users, because the screen-reader will read out loud the label when the user focus on the input element. The <label> element also help users who have difficulty clicking on very small regions (such as radio buttons or checkboxes) - because when the user clicks the text within the <label> element, it toggles the radio button/checkbox. The for attribute of the <label> tag should be equal to the id attribute of the <input> element to bind them together.
  • 23. The <select> Element The <select> element defines a drop-down list: <label for="cars">Choose a car:</label> <select id="cars" name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> The <option> elements defines an option that can be selected. By default, the first item in the drop-down list is selected. To define a pre-selected option, add the selected attribute to the option:
  • 24. The <select> Element Allow Multiple Selections: Use the multiple attribute to allow the user to select more than one value: <label for="cars">Choose a car:</label> <select id="cars" name="cars" size="4" multiple> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select>
  • 25. The <textarea> Element The <textarea> element defines a multi-line input field (a text area): <textarea name="message" rows="10" cols="30"> The cat was playing in the garden. </textarea> The rows attribute specifies the visible number of lines in a text area. The cols attribute specifies the visible width of a text area.
  • 26. The <fieldset> and <legend> Elements The <fieldset> element is used to group related data in a form. The <legend> element defines a caption for the <fieldset> element. <form action="/action_page.php"> <fieldset> <legend>Personalia:</legend> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"><br><br> <input type="submit" value="Submit"> </fieldset> </form>
  • 27. The <datalist> Element The <datalist> element specifies a list of pre-defined options for an <input> element. Users will see a drop-down list of the pre-defined options as they input data. The list attribute of the <input> element, must refer to the id attribute of the <datalist> element. <form action="/action_page.php"> <input list="browsers"> <datalist id="browsers"> <option value="Internet Explorer"> <option value="Firefox"> <option value="Chrome"> <option value="Opera"> <option value="Safari"> </datalist> </form>
  • 28. HTML Form Attributes The Action Attribute The action attribute defines the action to be performed when the form is submitted. Usually, the form data is sent to a file on the server when the user clicks on the submit button. In the example below, the form data is sent to a file called "action_page.php". This file contains a server-side script that handles the form data: On submit, send form data to "action_page.php": <form action="/action_page.php"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"><br><br> <input type="submit" value="Submit"> </form> If the action attribute is omitted, the action is set to the current page.
  • 29. The Target Attribute The target attribute specifies where to display the response that is received after submitting the form. The default value is _self which means that the response will open in the current window. Here, the submitted result will open in a new browser tab: <form action="/action_page.php" target="_blank">
  • 30. The Method Attribute The method attribute specifies the HTTP method to be used when submitting the form data. The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post"). The default HTTP method when submitting form data is GET. This example uses the GET method when submitting the form data: <form action="/action_page.php" method="get"> This example uses the POST method when submitting the form data: <form action="/action_page.php" method="post"> Always use POST if the form data contains sensitive or personal information!
  • 31. The Method Attribute Appends the form data to the URL, in name/value pairs NEVER use GET to send sensitive data! (the submitted form data is visible in the URL!) The length of a URL is limited (2048 characters) Useful for form submissions where a user wants to bookmark the result GET is good for non-secure data, like query strings in Google Appends the form data inside the body of the HTTP request (the submitted form data is not shown in the URL) POST has no size limitations, and can be used to send large amounts of data. Form submissions with POST cannot be bookmarked
  • 32. The Autocomplete Attribute The autocomplete attribute specifies whether a form should have autocomplete on or off. When autocomplete is on, the browser automatically complete values based on values that the user has entered before. A form with autocomplete on: <form action="/action_page.php" autocomplete="on">
  • 33. The Novalidate Attribute The novalidate attribute is a boolean attribute. When present, it specifies that the form-data (input) should not be validated when submitted. A form with a novalidate attribute: <form action="/action_page.php" novalidate>
  • 34. The Name Attribute for <input> Notice that each input field must have a name attribute to be submitted. If the name attribute is omitted, the value of the input field will not be sent at all. This example will not submit the value of the "First name" input field: <form action="/action_page.php"> <label for="fname">First name:</label><br> <input type="text" id="fname" value="John"><br><br> <input type="submit" value="Submit"> </form>
  • 35. Q & A