SlideShare une entreprise Scribd logo
1  sur  14
Web Forms and HTML
Lecture 4
Form In Html
Most of the HTML you write helps you display content and information for your
users.
Sometimes, however, you want a Web page to gather information from users
instead of giving static information to them.
HTML form markup tags give you a healthy collection of elements and attributes
for creating forms to collect information from visitors to your site.
HTML forms simply place a handful of GUI controls on the user agent to allow the
user to enter data.
After the data is entered into the fields, a special control is used to pass the
entered data on to a program that can do something useful with the data.
Such programs are typically referred to as form handlers because they “handle”
the form data.
You insert a form into your document by placing form fields within <form> tags.
Form Element
You insert a form into your document by placing form fields within <form>
tags.
All of the input elements associated with a single form are contained
within a <form> tag.
Syntax:
<form method=“get|post” action=“process.php”>
</form>
The action attribute defines a URL where the data from the form should
be sent to be “handled.”
The second attribute, method, controls how the data is sent to the
handler. The two valid values are get and post.
Get sends the form data to the form handler on the URL.
Post sends the form data in the Hypertext Transfer Protocol
(HTTP) header.
Difference Between “Get” And “Post”
Fundamental Difference is probably the Visibility -
GET request is sent via the URL string (appended to the URI with a question-mark as separator), which is visible.
POST request is encapsulated in the body of the HTTP request and can't be seen.
Length -
GET request goes via URL. Previously its length was approximately 255 characters long, in the modern browsers its
length is thousands of characters long (this is browser dependent).
No such maximum length limitation holds for the POST request for the obvious reason that it becomes a part of
the body of the HTTP request and there is no size limitation for the body of an HTTP request/response.
Type of Data -
GET request is sent via URL string and as we all know that URL can be text-only, so GET can carry only text data
POST has no such restriction and it can carry both text as well as binary data.
Caching/Bookmarking -
Again for the obvious reason that a GET request is nothing but an URL hence it can be cached as well as
Bookmarked.
No such luxuries with a POST request.
FORM Default -
GET is the default method of the HTML FORM element.
 To submit a FORM using POST method, we need to specify the method attribute and give it the value "POST".
Form Resubmission-
If Get method is used and if the page is refreshed it wouldn’t prompt before the request is resubmitted.
If Post method, would prompt request before the request is resubmitted if page is refreshed.
The specific purpose of get is to read something—to retrieve data from somewhere, dependent on the data sent.
post has the specific purpose of writing something (to a database, for example).
Form Fields
Form Fields and Buttons: input, textarea, and select
The input element is a way to take input from user, creating a different form
control depending on the value of its type attribute. The other two, textarea and
Select, create just one control type each. These elements will be looked at in
independent detail in few minutes, but there are a few characteristics common to
all three .
The Name Attribute:
If all the inputted data in a form was sent without anything to identify each piece
of data, a form-processing script wouldn’t know what piece of data is what.
The name attribute supplies this necessary identifier (such as <input
name=”book” />) and, in fact, the data in any input, textarea, or select form field
won’t be sent at all if there isn’t a name attribute present.
The Type Attribute:
With just this single element “Input” you can create 10 different types of controls
“Type” Attribute Values
text — for single-line text
password — for obfuscated text
checkbox — for a simple on or off
radio — for selecting one of a number of options
submit — for initiating the sending of the form data
reset — for returning the form fields to their original values
button — Simple button to perform some scripting on some event
Input Types
Input Type=“Text”
An input element with the attribute type=”text” is a single-line text box.
This is most common form field, used for short pieces of textual information such
as
someone’s name,
email address,
credit card number.
text is the default value for the type attribute (so you don’t need to explicitly use
the type attribute, if a textbox is what you’re after).
Other Attributes Of Text Filed are as follows:
value provides an initial value for the text input control that the user will see when
the form loads.
size allows you to specify the width of the text-input control in terms of characters.
maxlength allows you to specify the maximum number of characters a user can
enter into the text box.
Example:
<input type=“text” name=“name" maxlength=“3” size=“100” />
Input Types (contd.)
Input Type=“Password”
The password type works like the text type, apart from one characteristic:
As the user types, instead of the characters appearing in the text box, placeholder characters (usually
asterisks or circular bullets, depending on the browser) will appear in their place.
The idea behind this is that anyone peering over the user’s shoulder won’t be able to see what is being
typed in.
<input type="password" name="pword" maxlength=3 size=100 />
Input Type=“checkbox”:
The checkbox type creates a simple checkbox, used to supply a
yes/no,
set/unset,
on/off option.
By default, a browser will style this as a small empty square box, which, when selected, will display a “tick”
inside the box.
You can also specify that the initial state of a checkbox should be selected by adding the attribute and
value combination checked=”checked”.
If a checkbox is not selected when the form data is submitted, no value will be sent.
When the checkbox is selected, “on” will be sent as the value for the corresponding
name unless the tag has a value attribute, in which case the value of that will be sent for the name
instead.
<input type=”checkbox” name=”modern” checked=”checked” />
Input Types (contd.)
Input Type=“radio”
Radio buttons, defined by the radio type, are similar to checkboxes, but the idea is
that you can only select one option in a group at a time.
You give a group of radio input elements
the same name.
When one of the radio buttons in that group is selected, any other radio buttons
that were selected will be turned off.
<input type=”radio” name=”color” value=”red” checked=”checked” />
<input type=”radio” name=”color” value=”orange” />
<input type=”radio” name=”color” value=”blue” />
You really need to use the value attributes here.
Input Types (contd.)
Input Type “submit”
There are other ways of submitting form data (namely with a bit of JavaScript), but the most
common and easiest way is by hitting a submit button.
The submit input type takes the form of a button and when this button is pressed, the form data
will be sent to the value of the action attribute in the opening form tag.
but value can be changed with the value attribute.
<input type=”submit” value=”Search” />
Input Type “reset”:
The reset input type creates a reset button, which, when clicked (or otherwise .
selected), will reset the form, with form fields returning to the values that they had
when the page was first loaded.
Like submit, the text on the reset button (“Reset,” by default) can be changed with
the value attribute.
<input type=”reset” value=”Start again” />
With both submit and reset buttons, the name attribute isn’t particularly necessary.
Input Type= “button”:
Button input elements do absolutely nothing.
They are used to invoke client-side scripts (namely JavaScript)
<input type=”button” value=”Start again” />
Environment Variables
Beyond the variables you declare in your code, PHP has a collection of
environment variables, which are system defined variables that are
accessible from anywhere inside the PHP code
There are three environment variables used for Form Processing:
$_GET
$_POST
$_REQUEST
There are various reasons to be cautious about using the $_REQUEST[] ,
like what happens when we have a GET field and and POST field with the
same name.
Data returned from the client using the POST method are stored in the
$_POST[] Variable by PHP.
Data returned from the client using the GET method, or as a query string
in the URL, are stored in the $_GET[].
Assignments
1. Generate Dynamic Table using Forms
a. Create Page1 with Form consisting of Textfield - getting no: of Matematical tables
to print and a Submit Button.
b. Create a Page2 consisting of :
i. Mathematical Table in tablular format each cell consist of table starting from 1 to 12.
ii. The row of table shoud break after 4 cells.
iii. Program should be dynamic have variable of No: of table to generate.
2. Generate Text Fields using Forms
a. Create Page1 with Form consisting of Textfield - getting no: textfields to show
on Page2 and a Submit Button.
b. Create a Page2 consisting of :
No: of textfields given from page1.
c. Create a Page3 consisting of :
Values Given Through textfields on page2.
Assignments
3. Policies using Checkbox
a. Create a Page1 consisting of 5 check boxes :
a. Stepind
b. Discipline
c. Attendence
d. Assignment
e. Agree
f. A submit button
Requirement:
At least first 3 - maximum 4 and 5th check be selected show "Your are selected".
If first 3 or 4 are selected and last not then show fail message on page2.
If less than 3 are selected and last not-selected or selected then show fail message on page2.
Questions?

Contenu connexe

Tendances (20)

Forms in html5
Forms in html5Forms in html5
Forms in html5
 
Html class-04
Html class-04Html class-04
Html class-04
 
New Form Element in HTML5
New Form Element in HTML5New Form Element in HTML5
New Form Element in HTML5
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
 
20 html-forms
20 html-forms20 html-forms
20 html-forms
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
 
Html tables, forms and audio video
Html tables, forms and audio videoHtml tables, forms and audio video
Html tables, forms and audio video
 
Html Form Controls
Html Form ControlsHtml Form Controls
Html Form Controls
 
Html forms
Html formsHtml forms
Html forms
 
Html forms
Html formsHtml forms
Html forms
 
Building html forms
Building html formsBuilding html forms
Building html forms
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
Designing web pages html forms and input
Designing web pages html  forms and inputDesigning web pages html  forms and input
Designing web pages html forms and input
 
Javascript dom
Javascript domJavascript dom
Javascript dom
 
Php forms
Php formsPhp forms
Php forms
 
PHP Making Web Forms
PHP Making Web FormsPHP Making Web Forms
PHP Making Web Forms
 
Html forms
Html formsHtml forms
Html forms
 

Similaire à Web forms and html lecture Number 4

Similaire à Web forms and html lecture Number 4 (20)

CSS_Forms.pdf
CSS_Forms.pdfCSS_Forms.pdf
CSS_Forms.pdf
 
Html forms
Html formsHtml forms
Html forms
 
HTML
HTML HTML
HTML
 
Html forms
Html formsHtml forms
Html forms
 
HtmlForms- basic HTML forms description.
HtmlForms- basic HTML forms description.HtmlForms- basic HTML forms description.
HtmlForms- basic HTML forms description.
 
Html form
Html formHtml form
Html form
 
20-html-forms.ppt
20-html-forms.ppt20-html-forms.ppt
20-html-forms.ppt
 
11-html-forms.ppt
11-html-forms.ppt11-html-forms.ppt
11-html-forms.ppt
 
Forms with html5
Forms with html5Forms with html5
Forms with html5
 
Chapter 9: Forms
Chapter 9: FormsChapter 9: Forms
Chapter 9: Forms
 
05 html-forms
05 html-forms05 html-forms
05 html-forms
 
Chapter09
Chapter09Chapter09
Chapter09
 
Web design - Working with forms in HTML
Web design - Working with forms in HTMLWeb design - Working with forms in HTML
Web design - Working with forms in HTML
 
Html Xhtml And Xml 3e Tutorial 6
Html Xhtml And Xml 3e Tutorial 6Html Xhtml And Xml 3e Tutorial 6
Html Xhtml And Xml 3e Tutorial 6
 
Web topic 20 2 html forms
Web topic 20 2  html formsWeb topic 20 2  html forms
Web topic 20 2 html forms
 
Web topic 20 1 html forms
Web topic 20 1  html formsWeb topic 20 1  html forms
Web topic 20 1 html forms
 
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZerStd 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
 
Forms Part 1
Forms Part 1Forms Part 1
Forms Part 1
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 

Plus de Mudasir Syed

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php Mudasir Syed
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2Mudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDFMudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHPMudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1 Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminMudasir Syed
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joinsMudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagramMudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatinMudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 

Plus de Mudasir Syed (20)

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
 
Ajax
Ajax Ajax
Ajax
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
 
Sql select
Sql select Sql select
Sql select
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 

Dernier

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Dernier (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Web forms and html lecture Number 4

  • 1. Web Forms and HTML Lecture 4
  • 2. Form In Html Most of the HTML you write helps you display content and information for your users. Sometimes, however, you want a Web page to gather information from users instead of giving static information to them. HTML form markup tags give you a healthy collection of elements and attributes for creating forms to collect information from visitors to your site. HTML forms simply place a handful of GUI controls on the user agent to allow the user to enter data. After the data is entered into the fields, a special control is used to pass the entered data on to a program that can do something useful with the data. Such programs are typically referred to as form handlers because they “handle” the form data. You insert a form into your document by placing form fields within <form> tags.
  • 3. Form Element You insert a form into your document by placing form fields within <form> tags. All of the input elements associated with a single form are contained within a <form> tag. Syntax: <form method=“get|post” action=“process.php”> </form> The action attribute defines a URL where the data from the form should be sent to be “handled.” The second attribute, method, controls how the data is sent to the handler. The two valid values are get and post. Get sends the form data to the form handler on the URL. Post sends the form data in the Hypertext Transfer Protocol (HTTP) header.
  • 4. Difference Between “Get” And “Post” Fundamental Difference is probably the Visibility - GET request is sent via the URL string (appended to the URI with a question-mark as separator), which is visible. POST request is encapsulated in the body of the HTTP request and can't be seen. Length - GET request goes via URL. Previously its length was approximately 255 characters long, in the modern browsers its length is thousands of characters long (this is browser dependent). No such maximum length limitation holds for the POST request for the obvious reason that it becomes a part of the body of the HTTP request and there is no size limitation for the body of an HTTP request/response. Type of Data - GET request is sent via URL string and as we all know that URL can be text-only, so GET can carry only text data POST has no such restriction and it can carry both text as well as binary data. Caching/Bookmarking - Again for the obvious reason that a GET request is nothing but an URL hence it can be cached as well as Bookmarked. No such luxuries with a POST request. FORM Default - GET is the default method of the HTML FORM element.  To submit a FORM using POST method, we need to specify the method attribute and give it the value "POST". Form Resubmission- If Get method is used and if the page is refreshed it wouldn’t prompt before the request is resubmitted. If Post method, would prompt request before the request is resubmitted if page is refreshed. The specific purpose of get is to read something—to retrieve data from somewhere, dependent on the data sent. post has the specific purpose of writing something (to a database, for example).
  • 5. Form Fields Form Fields and Buttons: input, textarea, and select The input element is a way to take input from user, creating a different form control depending on the value of its type attribute. The other two, textarea and Select, create just one control type each. These elements will be looked at in independent detail in few minutes, but there are a few characteristics common to all three . The Name Attribute: If all the inputted data in a form was sent without anything to identify each piece of data, a form-processing script wouldn’t know what piece of data is what. The name attribute supplies this necessary identifier (such as <input name=”book” />) and, in fact, the data in any input, textarea, or select form field won’t be sent at all if there isn’t a name attribute present. The Type Attribute: With just this single element “Input” you can create 10 different types of controls
  • 6. “Type” Attribute Values text — for single-line text password — for obfuscated text checkbox — for a simple on or off radio — for selecting one of a number of options submit — for initiating the sending of the form data reset — for returning the form fields to their original values button — Simple button to perform some scripting on some event
  • 7. Input Types Input Type=“Text” An input element with the attribute type=”text” is a single-line text box. This is most common form field, used for short pieces of textual information such as someone’s name, email address, credit card number. text is the default value for the type attribute (so you don’t need to explicitly use the type attribute, if a textbox is what you’re after). Other Attributes Of Text Filed are as follows: value provides an initial value for the text input control that the user will see when the form loads. size allows you to specify the width of the text-input control in terms of characters. maxlength allows you to specify the maximum number of characters a user can enter into the text box. Example: <input type=“text” name=“name" maxlength=“3” size=“100” />
  • 8. Input Types (contd.) Input Type=“Password” The password type works like the text type, apart from one characteristic: As the user types, instead of the characters appearing in the text box, placeholder characters (usually asterisks or circular bullets, depending on the browser) will appear in their place. The idea behind this is that anyone peering over the user’s shoulder won’t be able to see what is being typed in. <input type="password" name="pword" maxlength=3 size=100 /> Input Type=“checkbox”: The checkbox type creates a simple checkbox, used to supply a yes/no, set/unset, on/off option. By default, a browser will style this as a small empty square box, which, when selected, will display a “tick” inside the box. You can also specify that the initial state of a checkbox should be selected by adding the attribute and value combination checked=”checked”. If a checkbox is not selected when the form data is submitted, no value will be sent. When the checkbox is selected, “on” will be sent as the value for the corresponding name unless the tag has a value attribute, in which case the value of that will be sent for the name instead. <input type=”checkbox” name=”modern” checked=”checked” />
  • 9. Input Types (contd.) Input Type=“radio” Radio buttons, defined by the radio type, are similar to checkboxes, but the idea is that you can only select one option in a group at a time. You give a group of radio input elements the same name. When one of the radio buttons in that group is selected, any other radio buttons that were selected will be turned off. <input type=”radio” name=”color” value=”red” checked=”checked” /> <input type=”radio” name=”color” value=”orange” /> <input type=”radio” name=”color” value=”blue” /> You really need to use the value attributes here.
  • 10. Input Types (contd.) Input Type “submit” There are other ways of submitting form data (namely with a bit of JavaScript), but the most common and easiest way is by hitting a submit button. The submit input type takes the form of a button and when this button is pressed, the form data will be sent to the value of the action attribute in the opening form tag. but value can be changed with the value attribute. <input type=”submit” value=”Search” /> Input Type “reset”: The reset input type creates a reset button, which, when clicked (or otherwise . selected), will reset the form, with form fields returning to the values that they had when the page was first loaded. Like submit, the text on the reset button (“Reset,” by default) can be changed with the value attribute. <input type=”reset” value=”Start again” /> With both submit and reset buttons, the name attribute isn’t particularly necessary. Input Type= “button”: Button input elements do absolutely nothing. They are used to invoke client-side scripts (namely JavaScript) <input type=”button” value=”Start again” />
  • 11. Environment Variables Beyond the variables you declare in your code, PHP has a collection of environment variables, which are system defined variables that are accessible from anywhere inside the PHP code There are three environment variables used for Form Processing: $_GET $_POST $_REQUEST There are various reasons to be cautious about using the $_REQUEST[] , like what happens when we have a GET field and and POST field with the same name. Data returned from the client using the POST method are stored in the $_POST[] Variable by PHP. Data returned from the client using the GET method, or as a query string in the URL, are stored in the $_GET[].
  • 12. Assignments 1. Generate Dynamic Table using Forms a. Create Page1 with Form consisting of Textfield - getting no: of Matematical tables to print and a Submit Button. b. Create a Page2 consisting of : i. Mathematical Table in tablular format each cell consist of table starting from 1 to 12. ii. The row of table shoud break after 4 cells. iii. Program should be dynamic have variable of No: of table to generate. 2. Generate Text Fields using Forms a. Create Page1 with Form consisting of Textfield - getting no: textfields to show on Page2 and a Submit Button. b. Create a Page2 consisting of : No: of textfields given from page1. c. Create a Page3 consisting of : Values Given Through textfields on page2.
  • 13. Assignments 3. Policies using Checkbox a. Create a Page1 consisting of 5 check boxes : a. Stepind b. Discipline c. Attendence d. Assignment e. Agree f. A submit button Requirement: At least first 3 - maximum 4 and 5th check be selected show "Your are selected". If first 3 or 4 are selected and last not then show fail message on page2. If less than 3 are selected and last not-selected or selected then show fail message on page2.