SlideShare a Scribd company logo
HTML
afm -INFO2301S1Y1314
FORMS
THE
Contents
 Relations between PHP and HTML forms
 Requirements for use of forms
 How form works
afm -INFO2301S1Y1314
The two important tasks in dynamic websites
I. Creating data
II. Processing Data
The relationships:
afm -INFO2301S1Y1314
Client-Server Interaction.
 Interaction between user and web application.
 Primary source of data (Client).
 Process data to cater business needs (records
keeping, financial report, application status, etc)
 HTML and Web scripting depend on each other to
form web application.
The importance of HTML forms
afm -INFO2301S1Y1314
 Knowledge in HTML.
 Strong foundation in Hypertext Markup Language is
a prerequisite.
 Knowing the HTML functions in the presentation
layer.
 Website design is central at HTML layer.
 Design and functionality should be balance in any
web application.
The importance of HTML forms
afm -INFO2301S1Y1314
The typical use of HTML forms
afm -INFO2301S1Y1314
 A form on a web page gathers input data from the user.
 The data the form controls varies e.g. buttons, text
fields, menus, etc.
 On the other hand the user's data is sent back to the
server where it is processed by web programming
languages, e.g. a PHP script
The functions of forms
afm -INFO2301S1Y1314
Example :
<html>
<form name:”fname” action =“input_dest.php” method=“post”>
<! - -
--- form inputs
- - >
</form>
<html>
 A form is an area that can contain form elements.
 Form elements are elements that allow the user to
enter information (like text fields, text area fields,
dropdown menus,radio buttons, checkboxes, etc.) in a
form.
 A form is defined with the <form> tag.
The functions of forms
afm -INFO2301S1Y1314
 An input form
 The most used form tag is the <input> tag.
 The type of input is specified with the type attribute.
 We will look at some of the most commonly used input
types.
 Text Field input
 Text fields are used when you want the user to type
letters, numbers, etc. in a form.
The functions of forms
afm -INFO2301S1Y1314
Example :
<form>
First name:
<input type="text" name="firstname"> <br>
Last name:
<input type="text" name="lastname">
</form>
 Radio Buttons
 Radio Buttons are used when you want the
user to select one of a limited number of
choices.
The functions of forms
afm -INFO2301S1Y1314
Example :
<form>
<input type="radio" name="sex“
value="male"> Male <br>
<input type="radio" name="sex" value="female">
Female
</form>
 Checkboxes
 Checkboxes are used when you want the user to
select one or more options of a limited number of
choices.
The functions of forms
afm -INFO2301S1Y1314
Example :
<form>
I have a bike: <input type="checkbox" name="vehicle"
value="Bike“> <br>
I have a car: <input type="checkbox" name="vehi cle"
value="Car“> <br>
I have an airplane: <input type="checkbox“ ame="vehicle"
value="Airplane
</form>
 Submit Buttons
 To be useful, a form will contain a submit button, which
the user can press to send the data to the server (or
whatever)
 Use an input element with attribute type="submit“.
 By default, the button has Submit Query written on it but
you can supply our own label using the value attribute.
The functions of forms
afm -INFO2301S1Y1314
Example :
<form>
<input type=“submit“ ></br>
<input type=“submit" value=“HANTAR" />
</form>
 The Form's Action Attribute and the Submit Button
 When the user clicks on the "Submit" button, the content of the form
is sent to the server.
 The form element has two attributes: action and method.
 The form's action attribute defines the name of the file to send the
content to.
 The file defined in the action attribute usually does something with the
received input.
The functions of forms
afm -INFO2301S1Y1314
Example :
<form>
name=“formName" action="html_form_submit.php“
method="get">
Username:
<input type="text" name="user">
<input type="submit" value=“submit">
</form>
 Reset button
 A form might contain a reset button, which the user
can press to clear the data s/he has typed
 Use an input element with attribute type="reset“.
 By default, the button has Reset written on it but
you can supply your own label using the value
attribute:
The functions of forms
afm -INFO2301S1Y1314
Example :
<form>
<input type="text" name="user">
<input type=“reset" value=“padam">
</form>
1. START with the HTML <form> tag
2. ACTION attribute of the <form> tag is the URL of
the PHP script that ill process the input data from the
form
3. METHOD on how to process the input data
i. GET (Default) = appends the form-data to the URL
in name/value pairs: RL?name=value&name=value
ii. POST = Sends the form-data as an HTTP post
transaction
4. CREATE the form with buttons, boxes, and others
using HTML tags and fields
5. SUBMIT button so that the form can be processed
6. END the form with the </form> tag. End the HTML
document with the </html> tag
Steps to make web forms
afm -INFO2301S1Y1314
<html>
<body>
<form name="input" action="html_form_action.php" method="get">
Type your first name:
<input type="text" name="FirstName" value="Mickey" size=“20”><br>
Type your last name:
<input type="text" name="LastName" value="Mouse" size=“20“><br>
<input type="radio" name="sex" value="male"> Male <br>
<input type="radio" name="sex" value="female"> Female
I have a bike: <input type="checkbox" name="vehicle" value="Bike“><br>
I have a car: <input type="checkbox" name="vehicle" value="Car"> <br>
<input type="submit" value="Submit">
</form>
<p>
If you click the "Submit" button, you will send your input to a new page called
html_form_action.php.
</p>
</body>
</html>
Steps to make web forms
afm -INFO2301S1Y1314
 When the user presses submit...
 When the submit button is pressed, the browser
arranges the data in name/value pairs
How a form works
afm -INFO2301S1Y1314
Example :
<form>
name=“formName" action="html_form_submit.php“
method="get">
Username:
<input type="text" name="username"> <-- user type mickey->
<input type="text" name=“surname"> <-- user type mouse->
<input type="submit" value=“submit">
</form>
 ..what happens in between the form & the server is ..
The data arranged in name/value pairs, behind the scenes
the browser also encodes the data using standard URL
encoding:
This replaces spaces, slashes and other chars that are not
allowed in URLs by their hexadecimal equivalents
 example 1: spaces are replaced by %20 (which may
display as '+'); slashes by %2F
Example 2: the user types Mickey and O Mouse into the
form The data is arranged and encoded as follows
firstname=Mickey&surname=O%20Mouse
How a form works
afm -INFO2301S1Y1314
 ..in the end at the server is ..
After the data is encoded, the browser creates an
HTTP request
 the command (method) is given by the method
attribute the URL is given by the action attribute if
method="get", the data is added to the end of the
URL after a question mark,
 e.g.: GET
process.php?firstname=Mickey&surname=Mouse
How a form works
afm -INFO2301S1Y1314
 an illustration..
How a form works
afm -INFO2301S1Y1314
 Notes on POST and GET methods
 Notes on GET:
 Appends form-data into the URL in name/value pairs
 The length of a URL is limited (about 3000 characters)
 Never use GET to send sensitive data! (will be visible in the
URL)
 Useful for form submissions where a user want to bookmark the
result
 GET is better for non-secure data, like query strings in Google
 Notes on POST:
 Appends form-data inside the body of the HTTP request (data is
not shown is in URL)
 Has no size limitations
 Form submissions with POST cannot be bookmarked
How a form works
afm -INFO2301S1Y1314
 Which method we need in form?
 GET
 The default method GET
 sends submitted data to the server by attaching it to the end of
the URL in ‘the query string’
 POST
 used if the processing of a form causes side effects, likethe
modification of a database, updating a shopping cart, or sending
an email message
 Sends submitted data to the server by bundling up the data and
put it into HTTP header message body
How a form works
afm -INFO2301S1Y1314
 PHP holds values from a form in 3 ways
1) The simple short style. Example :$name, $id
// Available if the PHP directive register_globals = on. As of
// PHP 4.2.0 the default value of register_globals = off.
// Using/relying on this method is not preferred.
2) The medium style. Example :$_GET[‘name’], $_POST[‘id’]
// Available since PHP 4.1.0
3) The long style. Example : $HTTP_GET_VARS[‘name’],
$HTTP_POST_VARS[‘id’]
// As of PHP 5.0.0, these long predefined variables can be
// disabled with the register_long_arrays directive.
How PHP communicate with HTML form
afm -INFO2301S1Y1314
How PHP communicate with HTML form
afm -INFO2301S1Y1314
 Example PHP codes on receiving ends..
<html>
<body>
<?php
// Medium style;
$name = $_GET['your_name'];
$phone = $_GET['your_phone'];
$email = $_GET['your_email_addr'];
$this_file_dir = $_SERVER['PHP_SELF'] ;
echo ‘You’ve registered as‘.$name.’<br>’;
echo ‘Your phone number is’.$phone.’<br>’;
echo ‘Your email’.$email.’<br>’;
echo ‘this php file directory/path is ‘. $this_file_dir;
?>
</body>
</html>
How PHP communicate with HTML form
afm -INFO2301S1Y1314
Quiz 1??
afm -INFO2301S1Y1314
HTML
afm -INFO2301S1Y1314
FORMS
THE

More Related Content

PPT
Chapter 07 php forms handling
Dhani Ahmad
 
PPT
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
DOCX
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
PDF
Making web forms using php
krishnapriya Tadepalli
 
PPTX
Form Handling using PHP
Nisa Soomro
 
PPTX
Php Form
lotlot
 
PPT
Lecture7 form processing by okello erick
okelloerick
 
PPTX
HTML5 Web Forms
Estelle Weyl
 
Chapter 07 php forms handling
Dhani Ahmad
 
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
Making web forms using php
krishnapriya Tadepalli
 
Form Handling using PHP
Nisa Soomro
 
Php Form
lotlot
 
Lecture7 form processing by okello erick
okelloerick
 
HTML5 Web Forms
Estelle Weyl
 

What's hot (20)

PPTX
Html 5 Forms
Jim Gerland
 
PPTX
Javascript
Nital Shingala
 
PDF
Creating simple php contact form
Daniel Downs
 
PPTX
Forms in html5
hrisi87
 
PPTX
Introduction to Javascript
ambuj pathak
 
PPTX
Web engineering - HTML Form
Nosheen Qamar
 
PDF
Database connectivity in PHP
Vineet Kumar Saini
 
PPT
05 html-forms
Palakshya
 
PDF
The Django Book - Chapter 7 forms
Vincent Chien
 
PDF
HTML5 Forms - KISS time - Fronteers
Robert Nyman
 
PPTX
PHP Training in Ambala ! Batra Computer Centre
jatin batra
 
PPTX
JavaScript Training in Ambala ! Batra Computer Centre
jatin batra
 
PPTX
04. session 04 working withformsandframes
Phúc Đỗ
 
PDF
Tadhg Bowe - i18n: how can I rephrase that?
Mage Titans ES
 
PPT
Html frames
Arslan Elahi
 
DOC
PHP form tutorial
Promb
 
PDF
Getting started-with-oracle-so a-iv
Amit Sharma
 
PPT
Introduction to XML
Jussi Pohjolainen
 
PPTX
Java script basic
Ravi Bhadauria
 
PDF
Introduction to HTML
Seble Nigussie
 
Html 5 Forms
Jim Gerland
 
Javascript
Nital Shingala
 
Creating simple php contact form
Daniel Downs
 
Forms in html5
hrisi87
 
Introduction to Javascript
ambuj pathak
 
Web engineering - HTML Form
Nosheen Qamar
 
Database connectivity in PHP
Vineet Kumar Saini
 
05 html-forms
Palakshya
 
The Django Book - Chapter 7 forms
Vincent Chien
 
HTML5 Forms - KISS time - Fronteers
Robert Nyman
 
PHP Training in Ambala ! Batra Computer Centre
jatin batra
 
JavaScript Training in Ambala ! Batra Computer Centre
jatin batra
 
04. session 04 working withformsandframes
Phúc Đỗ
 
Tadhg Bowe - i18n: how can I rephrase that?
Mage Titans ES
 
Html frames
Arslan Elahi
 
PHP form tutorial
Promb
 
Getting started-with-oracle-so a-iv
Amit Sharma
 
Introduction to XML
Jussi Pohjolainen
 
Java script basic
Ravi Bhadauria
 
Introduction to HTML
Seble Nigussie
 
Ad

Viewers also liked (9)

PPT
Using arrays with PHP for forms and storing information
Nicole Ryan
 
PPTX
PHP Forms PHP 05
mohamedsaad24
 
PDF
Creating And Consuming Web Services In Php 5
Michael Girouard
 
PPTX
3 php forms
hello8421
 
PPT
Php forms
Anne Lee
 
PPSX
Php creating forms
argusacademy
 
PDF
Forms and Databases in PHP
Mike Crabb
 
PDF
PHP and Web Services
Bruno Pedro
 
PDF
Creating Mobile Apps With PHP & Symfony2
Pablo Godel
 
Using arrays with PHP for forms and storing information
Nicole Ryan
 
PHP Forms PHP 05
mohamedsaad24
 
Creating And Consuming Web Services In Php 5
Michael Girouard
 
3 php forms
hello8421
 
Php forms
Anne Lee
 
Php creating forms
argusacademy
 
Forms and Databases in PHP
Mike Crabb
 
PHP and Web Services
Bruno Pedro
 
Creating Mobile Apps With PHP & Symfony2
Pablo Godel
 
Ad

Similar to 03 the htm_lforms (20)

PPT
Web forms and html lecture Number 4
Mudasir Syed
 
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
PPT
Html forms
M Vishnuvardhan Reddy
 
PPT
Web forms and html (lect 4)
Salman Memon
 
PPTX
Working with data.pptx
SherinRappai
 
PPTX
2-Chapter Edit.pptx debret tabour university
alemunuruhak9
 
PDF
CSS_Forms.pdf
gunjansingh599205
 
PDF
web2_lec6.pdf
ssuser893014
 
PDF
Web app development_php_07
Hassen Poreya
 
PPTX
Html form tag
shreyachougule
 
PPTX
Web forms - Learn web development (1).pptx
Zuŋɘʀa Aɓɗuɭɭʌh
 
PPT
Html class-04
Md Ali Hossain
 
PPTX
Web design - Working with forms in HTML
Mustafa Kamel Mohammadi
 
PPTX
Chapter 9: Forms
Steve Guinan
 
PPTX
HTML FORMS.pptx
Sierranaijamusic
 
PPT
Forms,Frames.ppt
MaheShiva
 
PPT
Forms,Frames.ppt
MaheShiva
 
PPT
Chapter9
DeAnna Gossett
 
PPTX
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web forms and html lecture Number 4
Mudasir Syed
 
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
cpbloger553
 
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
Web forms and html (lect 4)
Salman Memon
 
Working with data.pptx
SherinRappai
 
2-Chapter Edit.pptx debret tabour university
alemunuruhak9
 
CSS_Forms.pdf
gunjansingh599205
 
web2_lec6.pdf
ssuser893014
 
Web app development_php_07
Hassen Poreya
 
Html form tag
shreyachougule
 
Web forms - Learn web development (1).pptx
Zuŋɘʀa Aɓɗuɭɭʌh
 
Html class-04
Md Ali Hossain
 
Web design - Working with forms in HTML
Mustafa Kamel Mohammadi
 
Chapter 9: Forms
Steve Guinan
 
HTML FORMS.pptx
Sierranaijamusic
 
Forms,Frames.ppt
MaheShiva
 
Forms,Frames.ppt
MaheShiva
 
Chapter9
DeAnna Gossett
 
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 

More from IIUM (20)

PDF
How to use_000webhost
IIUM
 
PDF
Chapter 2
IIUM
 
PDF
Chapter 1
IIUM
 
PDF
Kreydle internship-multimedia
IIUM
 
PDF
03phpbldgblock
IIUM
 
PDF
Chap2 practice key
IIUM
 
PDF
Group p1
IIUM
 
PDF
Tutorial import n auto pilot blogspot friendly seo
IIUM
 
PDF
Visual sceneperception encycloperception-sage-oliva2009
IIUM
 
PDF
Exercise on algo analysis answer
IIUM
 
PDF
Redo midterm
IIUM
 
PDF
Heaps
IIUM
 
PDF
Report format
IIUM
 
PDF
Edpuzzle guidelines
IIUM
 
PDF
Final Exam Paper
IIUM
 
PDF
Final Exam Paper
IIUM
 
PDF
Group assignment 1 s21516
IIUM
 
PDF
Avl tree-rotations
IIUM
 
PDF
Week12 graph
IIUM
 
PDF
Vpn
IIUM
 
How to use_000webhost
IIUM
 
Chapter 2
IIUM
 
Chapter 1
IIUM
 
Kreydle internship-multimedia
IIUM
 
03phpbldgblock
IIUM
 
Chap2 practice key
IIUM
 
Group p1
IIUM
 
Tutorial import n auto pilot blogspot friendly seo
IIUM
 
Visual sceneperception encycloperception-sage-oliva2009
IIUM
 
Exercise on algo analysis answer
IIUM
 
Redo midterm
IIUM
 
Heaps
IIUM
 
Report format
IIUM
 
Edpuzzle guidelines
IIUM
 
Final Exam Paper
IIUM
 
Final Exam Paper
IIUM
 
Group assignment 1 s21516
IIUM
 
Avl tree-rotations
IIUM
 
Week12 graph
IIUM
 
Vpn
IIUM
 

Recently uploaded (20)

PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
How to Apply for a Job From Odoo 18 Website
Celine George
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 

03 the htm_lforms

  • 2. Contents  Relations between PHP and HTML forms  Requirements for use of forms  How form works afm -INFO2301S1Y1314
  • 3. The two important tasks in dynamic websites I. Creating data II. Processing Data The relationships: afm -INFO2301S1Y1314
  • 4. Client-Server Interaction.  Interaction between user and web application.  Primary source of data (Client).  Process data to cater business needs (records keeping, financial report, application status, etc)  HTML and Web scripting depend on each other to form web application. The importance of HTML forms afm -INFO2301S1Y1314
  • 5.  Knowledge in HTML.  Strong foundation in Hypertext Markup Language is a prerequisite.  Knowing the HTML functions in the presentation layer.  Website design is central at HTML layer.  Design and functionality should be balance in any web application. The importance of HTML forms afm -INFO2301S1Y1314
  • 6. The typical use of HTML forms afm -INFO2301S1Y1314
  • 7.  A form on a web page gathers input data from the user.  The data the form controls varies e.g. buttons, text fields, menus, etc.  On the other hand the user's data is sent back to the server where it is processed by web programming languages, e.g. a PHP script The functions of forms afm -INFO2301S1Y1314 Example : <html> <form name:”fname” action =“input_dest.php” method=“post”> <! - - --- form inputs - - > </form> <html>
  • 8.  A form is an area that can contain form elements.  Form elements are elements that allow the user to enter information (like text fields, text area fields, dropdown menus,radio buttons, checkboxes, etc.) in a form.  A form is defined with the <form> tag. The functions of forms afm -INFO2301S1Y1314
  • 9.  An input form  The most used form tag is the <input> tag.  The type of input is specified with the type attribute.  We will look at some of the most commonly used input types.  Text Field input  Text fields are used when you want the user to type letters, numbers, etc. in a form. The functions of forms afm -INFO2301S1Y1314 Example : <form> First name: <input type="text" name="firstname"> <br> Last name: <input type="text" name="lastname"> </form>
  • 10.  Radio Buttons  Radio Buttons are used when you want the user to select one of a limited number of choices. The functions of forms afm -INFO2301S1Y1314 Example : <form> <input type="radio" name="sex“ value="male"> Male <br> <input type="radio" name="sex" value="female"> Female </form>
  • 11.  Checkboxes  Checkboxes are used when you want the user to select one or more options of a limited number of choices. The functions of forms afm -INFO2301S1Y1314 Example : <form> I have a bike: <input type="checkbox" name="vehicle" value="Bike“> <br> I have a car: <input type="checkbox" name="vehi cle" value="Car“> <br> I have an airplane: <input type="checkbox“ ame="vehicle" value="Airplane </form>
  • 12.  Submit Buttons  To be useful, a form will contain a submit button, which the user can press to send the data to the server (or whatever)  Use an input element with attribute type="submit“.  By default, the button has Submit Query written on it but you can supply our own label using the value attribute. The functions of forms afm -INFO2301S1Y1314 Example : <form> <input type=“submit“ ></br> <input type=“submit" value=“HANTAR" /> </form>
  • 13.  The Form's Action Attribute and the Submit Button  When the user clicks on the "Submit" button, the content of the form is sent to the server.  The form element has two attributes: action and method.  The form's action attribute defines the name of the file to send the content to.  The file defined in the action attribute usually does something with the received input. The functions of forms afm -INFO2301S1Y1314 Example : <form> name=“formName" action="html_form_submit.php“ method="get"> Username: <input type="text" name="user"> <input type="submit" value=“submit"> </form>
  • 14.  Reset button  A form might contain a reset button, which the user can press to clear the data s/he has typed  Use an input element with attribute type="reset“.  By default, the button has Reset written on it but you can supply your own label using the value attribute: The functions of forms afm -INFO2301S1Y1314 Example : <form> <input type="text" name="user"> <input type=“reset" value=“padam"> </form>
  • 15. 1. START with the HTML <form> tag 2. ACTION attribute of the <form> tag is the URL of the PHP script that ill process the input data from the form 3. METHOD on how to process the input data i. GET (Default) = appends the form-data to the URL in name/value pairs: RL?name=value&name=value ii. POST = Sends the form-data as an HTTP post transaction 4. CREATE the form with buttons, boxes, and others using HTML tags and fields 5. SUBMIT button so that the form can be processed 6. END the form with the </form> tag. End the HTML document with the </html> tag Steps to make web forms afm -INFO2301S1Y1314
  • 16. <html> <body> <form name="input" action="html_form_action.php" method="get"> Type your first name: <input type="text" name="FirstName" value="Mickey" size=“20”><br> Type your last name: <input type="text" name="LastName" value="Mouse" size=“20“><br> <input type="radio" name="sex" value="male"> Male <br> <input type="radio" name="sex" value="female"> Female I have a bike: <input type="checkbox" name="vehicle" value="Bike“><br> I have a car: <input type="checkbox" name="vehicle" value="Car"> <br> <input type="submit" value="Submit"> </form> <p> If you click the "Submit" button, you will send your input to a new page called html_form_action.php. </p> </body> </html> Steps to make web forms afm -INFO2301S1Y1314
  • 17.  When the user presses submit...  When the submit button is pressed, the browser arranges the data in name/value pairs How a form works afm -INFO2301S1Y1314 Example : <form> name=“formName" action="html_form_submit.php“ method="get"> Username: <input type="text" name="username"> <-- user type mickey-> <input type="text" name=“surname"> <-- user type mouse-> <input type="submit" value=“submit"> </form>
  • 18.  ..what happens in between the form & the server is .. The data arranged in name/value pairs, behind the scenes the browser also encodes the data using standard URL encoding: This replaces spaces, slashes and other chars that are not allowed in URLs by their hexadecimal equivalents  example 1: spaces are replaced by %20 (which may display as '+'); slashes by %2F Example 2: the user types Mickey and O Mouse into the form The data is arranged and encoded as follows firstname=Mickey&surname=O%20Mouse How a form works afm -INFO2301S1Y1314
  • 19.  ..in the end at the server is .. After the data is encoded, the browser creates an HTTP request  the command (method) is given by the method attribute the URL is given by the action attribute if method="get", the data is added to the end of the URL after a question mark,  e.g.: GET process.php?firstname=Mickey&surname=Mouse How a form works afm -INFO2301S1Y1314
  • 20.  an illustration.. How a form works afm -INFO2301S1Y1314
  • 21.  Notes on POST and GET methods  Notes on GET:  Appends form-data into the URL in name/value pairs  The length of a URL is limited (about 3000 characters)  Never use GET to send sensitive data! (will be visible in the URL)  Useful for form submissions where a user want to bookmark the result  GET is better for non-secure data, like query strings in Google  Notes on POST:  Appends form-data inside the body of the HTTP request (data is not shown is in URL)  Has no size limitations  Form submissions with POST cannot be bookmarked How a form works afm -INFO2301S1Y1314
  • 22.  Which method we need in form?  GET  The default method GET  sends submitted data to the server by attaching it to the end of the URL in ‘the query string’  POST  used if the processing of a form causes side effects, likethe modification of a database, updating a shopping cart, or sending an email message  Sends submitted data to the server by bundling up the data and put it into HTTP header message body How a form works afm -INFO2301S1Y1314
  • 23.  PHP holds values from a form in 3 ways 1) The simple short style. Example :$name, $id // Available if the PHP directive register_globals = on. As of // PHP 4.2.0 the default value of register_globals = off. // Using/relying on this method is not preferred. 2) The medium style. Example :$_GET[‘name’], $_POST[‘id’] // Available since PHP 4.1.0 3) The long style. Example : $HTTP_GET_VARS[‘name’], $HTTP_POST_VARS[‘id’] // As of PHP 5.0.0, these long predefined variables can be // disabled with the register_long_arrays directive. How PHP communicate with HTML form afm -INFO2301S1Y1314
  • 24. How PHP communicate with HTML form afm -INFO2301S1Y1314
  • 25.  Example PHP codes on receiving ends.. <html> <body> <?php // Medium style; $name = $_GET['your_name']; $phone = $_GET['your_phone']; $email = $_GET['your_email_addr']; $this_file_dir = $_SERVER['PHP_SELF'] ; echo ‘You’ve registered as‘.$name.’<br>’; echo ‘Your phone number is’.$phone.’<br>’; echo ‘Your email’.$email.’<br>’; echo ‘this php file directory/path is ‘. $this_file_dir; ?> </body> </html> How PHP communicate with HTML form afm -INFO2301S1Y1314