SlideShare a Scribd company logo
1 of 25
PHP Forms
 GET and POST Method
 Form Validation
 Form Required Fields
*Property of STI K0032
GET and POST Method
A form data can be submitted using POST
and GET method
Both are used for same purpose but stand
apart for some specifications
GET and POST create an array which holds
key/value pairs, where keys are the name of
the form controls and values are the input
data by the user
*Property of STI K0032
GET and POST Method
Both GET and POST method are treated as
$_GET and $_POST in PHP
These methods are superglobals, which
means that they are always accessible, and
they can be accessed using any function,
class or file
The $_GET method is an associative array of
variables passed to the current script via the
URL parameters
*Property of STI K0032
GET and POST Method
The $_POST method is an array of variables
passed to the current script via the HTTP
POST method
In this method the information is
transferred in a hidden manner
A form that submits information is
appended to the URL in the form of Query
String which consists of name = value pairs
in URL known as URL Encoding
*Property of STI K0032
GET and POST Method
This string contains user values/data, which
are joined using equal (=) signs, separated
by ampersand (&), and spaces are removed
and replaced with plus (+) sign
Name1=value1&name2=value2&name3=value3
*Property of STI K0032
Get Method
 http:/.www.example.com/index.html?
name=mel@email.com&contact=09176543210
 The code below is a client-side HTML form using
method=“get” for user to fill the information
*Property of STI K0032
Get Method
 The code below is the server-side PHP script
where, $_GET associative array is used to receive
sent information from server end
*Property of STI K0032
Post Method
<form action="#" method="post">
....
</form>
Below is a server-side PHP script where $_POST associative
array is used to receive sent information at server end
*Property of STI K0032
Form validation
*Property of STI K0032
Form validation
The form shown in Figure 6.1 consists of the
following elements:
 Name (required field - must contain letters and
whitespaces)
 E-mail (required field - must contain valid email address)
 Website (optional field - if present, must contain valid
website URL)
 Comments (optional field - a multi-line text field)
 Gender (required field - must select a radio button )
*Property of STI K0032
Form Elements
The Name, E-mail, Website are input
elements
Input elements, in particular, used text and
submit values for its types attribute in order
to create text fields and buttons
The HTML code:
*Property of STI K0032
Form Elements
Radio button shows several options to the
users from which the user may select one
HTML Code:
*Property of STI K0032
Form Elements
The text area is typically a large text field
with multiple rows
The textarea element has three attributes –
name, rows, and cols attribute
HTML code:
*Property of STI K0032
Form Elements
 list element offers options from which the user might
choose. A list can be created using the select element,
within which is nested option elements for each option to
appear
 The select element has a name attribute giving the name
for the browser to use when identifying the selection
when the form is submitted
 The option element has a value attribute for specifying
what value to send when that option is selected, and it has
a select attribute which allows the HTML to specify which
option is initially selected. The code
*Property of STI K0032
Form Elements
 HTML Code:
*Property of STI K0032
Form Element
 The HTML code of the form element:
 when the form is submitted, the form data is sent with
method=”post”
 So, the $_SERVER["PHP_SELF"] sends the submitted
forms data to the page itself, instead of jumping to a
different page
*Property of STI K0032
Form Element
 The $_SERVER["PHP_SELF"] is a super global
variable that returns the filename of the currently
executing script
 Htmlspecialchars() function converts special
characters to HTML entities
 Cross-site scripting (XSS) is a type of computer
security vulnerability typically found inWeb
application
*Property of STI K0032
Form Element
 Example: test_form.php
 if a user enters the normal URL in the address bar like
"http://www.example.com/test_form.php", the above code
will be translated to:
*Property of STI K0032
Form Element
 consider that if a user enters the following URL in
the address bar:
http://www.example.com/test_form.php/%22%3E
%3Cscript%3Ealert('hacked')%3C/script%3E
 will be translated to:
*Property of STI K0032
Form Element
be aware that any JavaScript code can
be added inside the <script> tag
A hacker can redirect the user to a file on
another server, and that file can hold
malicious code that can alter the global
variables or submit the form to another
address to save the user’s data
*Property of STI K0032
how to avoid $_SERVER[“PHP_SELF”] exploit?
The $_SERVER[“PHP_SELF”] exploit can be
avoided using the htmlspecialchars()
function
if the user tries to exploit the PHP_SELF
variable, it will result:
*Property of STI K0032
Validate Form Data with PHP
 The very first thing to do to validate form data with PHP is
to pass all variables through PHP’s htmlspecialchars()
function
 For example:
 With htmlspecialchars() function it would not be executed,
because it would be saved as HTML escaped code like this:
*Property of STI K0032
test_input()
*Property of STI K0032
Form Required Fields
 In the previous slide, all input fields were optional,
meaning no required fields to be filled in by the
user
 Here is a simple PHP script that checks the name
for empty input and throws an error message if
the input is empty:
*Property of STI K0032
Form Required Fields
To display the error message in the HTML form (this
will be generated if the user tries to submit the form
without filling in the required fields) use the code
below:

More Related Content

What's hot

Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
mussawir20
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
club23
 

What's hot (20)

Web Technology Lab files with practical
Web Technology Lab  files with practicalWeb Technology Lab  files with practical
Web Technology Lab files with practical
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
PHP Form Validation Technique
PHP Form Validation TechniquePHP Form Validation Technique
PHP Form Validation Technique
 
Html forms
Html formsHtml forms
Html forms
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Html form tag
Html form tagHtml form tag
Html form tag
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
Operators php
Operators phpOperators php
Operators php
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 

Viewers also liked

Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
Harit Kothari
 
Php Form
Php FormPhp Form
Php Form
lotlot
 
Creating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemCreating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHP
Thomas Weinert
 
Geek Austin PHP Class - Session 4
Geek Austin PHP Class - Session 4Geek Austin PHP Class - Session 4
Geek Austin PHP Class - Session 4
jimbojsb
 
S.G.Balaji Resume
S.G.Balaji ResumeS.G.Balaji Resume
S.G.Balaji Resume
Balaji Sg
 

Viewers also liked (20)

3 php forms
3 php forms3 php forms
3 php forms
 
Chapter 07 php forms handling
Chapter 07   php forms handlingChapter 07   php forms handling
Chapter 07 php forms handling
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
Php Form
Php FormPhp Form
Php Form
 
Making web forms using php
Making web forms using phpMaking web forms using php
Making web forms using php
 
Get method and post method
Get method and post methodGet method and post method
Get method and post method
 
Creating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemCreating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login System
 
Forms and Databases in PHP
Forms and Databases in PHPForms and Databases in PHP
Forms and Databases in PHP
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
PHP Making Web Forms
PHP Making Web FormsPHP Making Web Forms
PHP Making Web Forms
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHP
 
Script login form php
Script login form phpScript login form php
Script login form php
 
Get and post methods
Get and post methodsGet and post methods
Get and post methods
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
 
Geek Austin PHP Class - Session 4
Geek Austin PHP Class - Session 4Geek Austin PHP Class - Session 4
Geek Austin PHP Class - Session 4
 
S.G.Balaji Resume
S.G.Balaji ResumeS.G.Balaji Resume
S.G.Balaji Resume
 
Ns3
Ns3Ns3
Ns3
 

Similar to Php forms

Web forms and html lecture Number 4
Web forms and html lecture Number 4Web forms and html lecture Number 4
Web forms and html lecture Number 4
Mudasir Syed
 
9780538745840 ppt ch04
9780538745840 ppt ch049780538745840 ppt ch04
9780538745840 ppt ch04
Terry Yoast
 
Html5ppt
Html5pptHtml5ppt
Html5ppt
recroup
 
Common gateway interface
Common gateway interfaceCommon gateway interface
Common gateway interface
Anandita
 

Similar to Php forms (20)

forms.pptx
forms.pptxforms.pptx
forms.pptx
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
 
Web forms and html lecture Number 4
Web forms and html lecture Number 4Web forms and html lecture Number 4
Web forms and html lecture Number 4
 
Html forms
Html formsHtml forms
Html forms
 
Chapter09
Chapter09Chapter09
Chapter09
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
 
Html forms
Html formsHtml forms
Html forms
 
9780538745840 ppt ch04
9780538745840 ppt ch049780538745840 ppt ch04
9780538745840 ppt ch04
 
331592291-HTML-and-Cascading style sheet
331592291-HTML-and-Cascading style sheet331592291-HTML-and-Cascading style sheet
331592291-HTML-and-Cascading style sheet
 
Html5ppt
Html5pptHtml5ppt
Html5ppt
 
New Form Element in HTML5
New Form Element in HTML5New Form Element in HTML5
New Form Element in HTML5
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
 
FORMS IN PHP contains various tags and code
FORMS IN PHP contains various tags and codeFORMS IN PHP contains various tags and code
FORMS IN PHP contains various tags and code
 
Cgi
CgiCgi
Cgi
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2
 
Web I - 04 - Forms
Web I - 04 - FormsWeb I - 04 - Forms
Web I - 04 - Forms
 
Common gateway interface
Common gateway interfaceCommon gateway interface
Common gateway interface
 
web2_lec6.pdf
web2_lec6.pdfweb2_lec6.pdf
web2_lec6.pdf
 
Html5
Html5Html5
Html5
 

More from Anne Lee

03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE
Anne Lee
 
02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES
02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES
02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES
Anne Lee
 
01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION
01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION
01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION
Anne Lee
 

More from Anne Lee (20)

Week 17 slides 1 7 multidimensional, parallel, and distributed database
Week 17 slides 1 7 multidimensional, parallel, and distributed databaseWeek 17 slides 1 7 multidimensional, parallel, and distributed database
Week 17 slides 1 7 multidimensional, parallel, and distributed database
 
Data mining
Data miningData mining
Data mining
 
Data warehousing
Data warehousingData warehousing
Data warehousing
 
Database backup and recovery
Database backup and recoveryDatabase backup and recovery
Database backup and recovery
 
Database monitoring and performance management
Database monitoring and performance managementDatabase monitoring and performance management
Database monitoring and performance management
 
transportation and assignment models
transportation and assignment modelstransportation and assignment models
transportation and assignment models
 
Database Security Slide Handout
Database Security Slide HandoutDatabase Security Slide Handout
Database Security Slide Handout
 
Database Security Handout
Database Security HandoutDatabase Security Handout
Database Security Handout
 
Database Security - IG
Database Security - IGDatabase Security - IG
Database Security - IG
 
03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE
 
02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES
02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES
02 laboratory exercise 1 - RETRIEVING DATA FROM SEVERAL TABLES
 
01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION
01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION
01 laboratory exercise 1 - DESIGN A SIMPLE DATABASE APPLICATION
 
Indexes - INSTRUCTOR'S GUIDE
Indexes - INSTRUCTOR'S GUIDEIndexes - INSTRUCTOR'S GUIDE
Indexes - INSTRUCTOR'S GUIDE
 
07 ohp slides 1 - INDEXES
07 ohp slides 1 - INDEXES07 ohp slides 1 - INDEXES
07 ohp slides 1 - INDEXES
 
07 ohp slide handout 1 - INDEXES
07 ohp slide handout 1 - INDEXES07 ohp slide handout 1 - INDEXES
07 ohp slide handout 1 - INDEXES
 
Wk 16 ses 43 45 makrong kasanayan sa pagsusulat
Wk 16 ses 43 45 makrong kasanayan sa pagsusulatWk 16 ses 43 45 makrong kasanayan sa pagsusulat
Wk 16 ses 43 45 makrong kasanayan sa pagsusulat
 
Wk 15 ses 40 42 makrong kasanayan sa pagbabasa
Wk 15 ses 40 42 makrong kasanayan sa pagbabasaWk 15 ses 40 42 makrong kasanayan sa pagbabasa
Wk 15 ses 40 42 makrong kasanayan sa pagbabasa
 
Wk 13 ses 35 37 makrong kasanayan sa pagsasalita
Wk 13 ses 35 37 makrong kasanayan sa pagsasalitaWk 13 ses 35 37 makrong kasanayan sa pagsasalita
Wk 13 ses 35 37 makrong kasanayan sa pagsasalita
 
Wk 12 ses 32 34 makrong kasanayan sa pakikinig
Wk 12 ses 32 34 makrong kasanayan sa pakikinigWk 12 ses 32 34 makrong kasanayan sa pakikinig
Wk 12 ses 32 34 makrong kasanayan sa pakikinig
 
Wk 11 ses 29 31 konseptong pangkomunikasyon - FILIPINO 1
Wk 11 ses 29 31 konseptong pangkomunikasyon - FILIPINO 1Wk 11 ses 29 31 konseptong pangkomunikasyon - FILIPINO 1
Wk 11 ses 29 31 konseptong pangkomunikasyon - FILIPINO 1
 

Recently uploaded

6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Sheetaleventcompany
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 

Recently uploaded (20)

(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 

Php forms

  • 1. PHP Forms  GET and POST Method  Form Validation  Form Required Fields
  • 2. *Property of STI K0032 GET and POST Method A form data can be submitted using POST and GET method Both are used for same purpose but stand apart for some specifications GET and POST create an array which holds key/value pairs, where keys are the name of the form controls and values are the input data by the user
  • 3. *Property of STI K0032 GET and POST Method Both GET and POST method are treated as $_GET and $_POST in PHP These methods are superglobals, which means that they are always accessible, and they can be accessed using any function, class or file The $_GET method is an associative array of variables passed to the current script via the URL parameters
  • 4. *Property of STI K0032 GET and POST Method The $_POST method is an array of variables passed to the current script via the HTTP POST method In this method the information is transferred in a hidden manner A form that submits information is appended to the URL in the form of Query String which consists of name = value pairs in URL known as URL Encoding
  • 5. *Property of STI K0032 GET and POST Method This string contains user values/data, which are joined using equal (=) signs, separated by ampersand (&), and spaces are removed and replaced with plus (+) sign Name1=value1&name2=value2&name3=value3
  • 6. *Property of STI K0032 Get Method  http:/.www.example.com/index.html? name=mel@email.com&contact=09176543210  The code below is a client-side HTML form using method=“get” for user to fill the information
  • 7. *Property of STI K0032 Get Method  The code below is the server-side PHP script where, $_GET associative array is used to receive sent information from server end
  • 8. *Property of STI K0032 Post Method <form action="#" method="post"> .... </form> Below is a server-side PHP script where $_POST associative array is used to receive sent information at server end
  • 9. *Property of STI K0032 Form validation
  • 10. *Property of STI K0032 Form validation The form shown in Figure 6.1 consists of the following elements:  Name (required field - must contain letters and whitespaces)  E-mail (required field - must contain valid email address)  Website (optional field - if present, must contain valid website URL)  Comments (optional field - a multi-line text field)  Gender (required field - must select a radio button )
  • 11. *Property of STI K0032 Form Elements The Name, E-mail, Website are input elements Input elements, in particular, used text and submit values for its types attribute in order to create text fields and buttons The HTML code:
  • 12. *Property of STI K0032 Form Elements Radio button shows several options to the users from which the user may select one HTML Code:
  • 13. *Property of STI K0032 Form Elements The text area is typically a large text field with multiple rows The textarea element has three attributes – name, rows, and cols attribute HTML code:
  • 14. *Property of STI K0032 Form Elements  list element offers options from which the user might choose. A list can be created using the select element, within which is nested option elements for each option to appear  The select element has a name attribute giving the name for the browser to use when identifying the selection when the form is submitted  The option element has a value attribute for specifying what value to send when that option is selected, and it has a select attribute which allows the HTML to specify which option is initially selected. The code
  • 15. *Property of STI K0032 Form Elements  HTML Code:
  • 16. *Property of STI K0032 Form Element  The HTML code of the form element:  when the form is submitted, the form data is sent with method=”post”  So, the $_SERVER["PHP_SELF"] sends the submitted forms data to the page itself, instead of jumping to a different page
  • 17. *Property of STI K0032 Form Element  The $_SERVER["PHP_SELF"] is a super global variable that returns the filename of the currently executing script  Htmlspecialchars() function converts special characters to HTML entities  Cross-site scripting (XSS) is a type of computer security vulnerability typically found inWeb application
  • 18. *Property of STI K0032 Form Element  Example: test_form.php  if a user enters the normal URL in the address bar like "http://www.example.com/test_form.php", the above code will be translated to:
  • 19. *Property of STI K0032 Form Element  consider that if a user enters the following URL in the address bar: http://www.example.com/test_form.php/%22%3E %3Cscript%3Ealert('hacked')%3C/script%3E  will be translated to:
  • 20. *Property of STI K0032 Form Element be aware that any JavaScript code can be added inside the <script> tag A hacker can redirect the user to a file on another server, and that file can hold malicious code that can alter the global variables or submit the form to another address to save the user’s data
  • 21. *Property of STI K0032 how to avoid $_SERVER[“PHP_SELF”] exploit? The $_SERVER[“PHP_SELF”] exploit can be avoided using the htmlspecialchars() function if the user tries to exploit the PHP_SELF variable, it will result:
  • 22. *Property of STI K0032 Validate Form Data with PHP  The very first thing to do to validate form data with PHP is to pass all variables through PHP’s htmlspecialchars() function  For example:  With htmlspecialchars() function it would not be executed, because it would be saved as HTML escaped code like this:
  • 23. *Property of STI K0032 test_input()
  • 24. *Property of STI K0032 Form Required Fields  In the previous slide, all input fields were optional, meaning no required fields to be filled in by the user  Here is a simple PHP script that checks the name for empty input and throws an error message if the input is empty:
  • 25. *Property of STI K0032 Form Required Fields To display the error message in the HTML form (this will be generated if the user tries to submit the form without filling in the required fields) use the code below: