SlideShare a Scribd company logo
CN5109
WEB APPLICATION
DEVELOPMENT
Chapter 5
PHP Form
PHP Form
• A Form is a document that containing black fields, that the
user can fill the data or user can select the data.
• Casually the data will store in the data base.
• When the user fills out the form and clicks the submit button,
the form data is sent for processing to a PHP file.
• The form data is sent with the HTTP POST or GET method.
PHP Form
• Example PHP Form using HTML POST method:
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
PHP Form
• To display the submitted data you could simply echo all the
variables.
• The "welcome.php" looks like this:
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
PHP Form
• The same result could also be achieved using the HTTP GET
method:
<body>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
PHP Form
• The "welcome_get.php" looks like this:
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
GET vs. POST
• Both GET and POST create an array (e.g. array( key => value,
key2 => value2, key3 => value3, ...)).
• This array holds key/value pairs, where keys are the names of
the form controls and values are the input data from the user.
• $_GET is an array of variables passed to the current script via
the URL parameters.
• $_POST is an array of variables passed to the current script via
the HTTP POST method.
GET vs. POST
• Information sent from a form with the GET method is visible
to everyone (all variable names and values are displayed in
the URL).
• GET also has limits on the amount of information to send.
• The limitation is about 2000 characters.
• GET may be used for sending non-sensitive data.
GET vs. POST
• Information sent from a form with the POST method is
invisible to others (all names/values are embedded within the
body of the HTTP request) and has no limits on the amount of
information to send.
• POST supports advanced functionality such as support for
multi-part binary input while uploading files to server.
Form Validation
• Validation means check the input submitted by the user.
• Proper validation of form data is important to protect your
form from hackers and spammers!
• There are two types of validation are available in PHP.
• They are as follows:
• Client-Side Validation − Validation is performed on the
client machine web browsers.
• Server Side Validation − After submitted by data, The
data has sent to a server and perform validation
checks in server machine.
Example
• Below code shows validation of URL:
• Below code shows validation of Email address
$website = input($_POST["site"]);
if (!preg_match("/b(?:(?:https?|ftp)://|www.)[-a-z0-
9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i",$website))
{
$websiteErr = "Invalid URL";
}
$email = input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid format and please re-enter valid email";
}
Example
• The code below shows a simple way to check if the name field
only contains letters and whitespace.
• If the value of the name field is not valid, then store an error
message:
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name))
{
$nameErr = "Only letters and white space allowed";
}
preg_match – this function is used to perform a pattern match on a
string. It returns true if a match is found and false if a match is not found.
Example
• In the code below, if the e-mail address is not well-formed,
then store an error message:
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email format";
}

More Related Content

PDF
GET and POST in PHP
Vineet Kumar Saini
 
PPT
Php forms
Anne Lee
 
PDF
PHP Making Web Forms
krishnapriya Tadepalli
 
PDF
Making web forms using php
krishnapriya Tadepalli
 
PPTX
Form Handling using PHP
Nisa Soomro
 
PPTX
HTTP
jangezkhan
 
PPTX
PHP Form Validation Technique
Morshedul Arefin
 
PPTX
Url and http
matthewzook
 
GET and POST in PHP
Vineet Kumar Saini
 
Php forms
Anne Lee
 
PHP Making Web Forms
krishnapriya Tadepalli
 
Making web forms using php
krishnapriya Tadepalli
 
Form Handling using PHP
Nisa Soomro
 
PHP Form Validation Technique
Morshedul Arefin
 
Url and http
matthewzook
 

What's hot (13)

PDF
Le Wagon - Web 101
Edward_Schults
 
PPTX
uptu web technology unit 2 html
Abhishek Kesharwani
 
PDF
Understanding the Web through HTTP
Olivia Brundage
 
PPTX
SCWCD : The web client model
Ben Abdallah Helmi
 
PPTX
Get method and post method
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Get_vs_Post
Ashwin Perti
 
PPTX
Get and post methods in php - phpgurukul
PHPGurukul Blog
 
ODP
Form Processing In Php
Harit Kothari
 
PPTX
Hypertext Transfer Protocol
Rajan Pandey
 
PDF
Imec tcbl single_sign_on_extra
TCBL Project
 
PPTX
Http and its Applications
Nayan Dagliya
 
Le Wagon - Web 101
Edward_Schults
 
uptu web technology unit 2 html
Abhishek Kesharwani
 
Understanding the Web through HTTP
Olivia Brundage
 
SCWCD : The web client model
Ben Abdallah Helmi
 
Get_vs_Post
Ashwin Perti
 
Get and post methods in php - phpgurukul
PHPGurukul Blog
 
Form Processing In Php
Harit Kothari
 
Hypertext Transfer Protocol
Rajan Pandey
 
Imec tcbl single_sign_on_extra
TCBL Project
 
Http and its Applications
Nayan Dagliya
 
Ad

Similar to Web Application Development using PHP Chapter 5 (20)

PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
PPTX
Working with data.pptx
SherinRappai
 
PPTX
2-Chapter Edit.pptx debret tabour university
alemunuruhak9
 
PDF
Web Development Course: PHP lecture 2
Gheyath M. Othman
 
PPTX
forms.pptx
asmabagersh
 
PDF
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Working with Data and built-in functions of PHP
mohanaps
 
PPTX
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PPT
PHP-04-Forms.ppt
NatureLifearabhi
 
PPT
PHP-04-Forms PHP-04-Forms PHP-04-Forms PHP-04-Forms
ZahraWaheed9
 
PDF
web2_lec6.pdf
ssuser893014
 
DOCX
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
PPTX
A179178417_21_2025_PHP Get and Post.pptx
malikanuj0151
 
PPTX
SCWCD : The web client model : CHAP : 1
Ben Abdallah Helmi
 
PDF
Php, mysq lpart4(processing html form)
Subhasis Nayak
 
PPTX
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
harleensingh985
 
PPT
Lecture7 form processing by okello erick
okelloerick
 
PPTX
Chapter 6 Getting Data from the Client (1).pptx
AhmedKafi7
 
PPTX
Web Hacking Series Part 1
Aditya Kamat
 
PDF
0_Leksion_Web_Servers (1).pdf
Zani10
 
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
Working with data.pptx
SherinRappai
 
2-Chapter Edit.pptx debret tabour university
alemunuruhak9
 
Web Development Course: PHP lecture 2
Gheyath M. Othman
 
forms.pptx
asmabagersh
 
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
Working with Data and built-in functions of PHP
mohanaps
 
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PHP-04-Forms.ppt
NatureLifearabhi
 
PHP-04-Forms PHP-04-Forms PHP-04-Forms PHP-04-Forms
ZahraWaheed9
 
web2_lec6.pdf
ssuser893014
 
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
A179178417_21_2025_PHP Get and Post.pptx
malikanuj0151
 
SCWCD : The web client model : CHAP : 1
Ben Abdallah Helmi
 
Php, mysq lpart4(processing html form)
Subhasis Nayak
 
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
harleensingh985
 
Lecture7 form processing by okello erick
okelloerick
 
Chapter 6 Getting Data from the Client (1).pptx
AhmedKafi7
 
Web Hacking Series Part 1
Aditya Kamat
 
0_Leksion_Web_Servers (1).pdf
Zani10
 
Ad

More from Mohd Harris Ahmad Jaal (20)

PPT
Fundamentals of Programming Chapter 7
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Programming Chapter 4
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Programming Chapter 3
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Programming Chapter 2
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Programming Chapter 1
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
PPTX
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Computing Chapter 10
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Computing Chapter 9
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Computing Chapter 8
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Computing Chapter 7
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Computing Chapter 6
Mohd Harris Ahmad Jaal
 
PPT
Fundamentals of Computing Chapter 5
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 4
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 3
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 2
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 1
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 10
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 9
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 8
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 5
Mohd Harris Ahmad Jaal
 

Recently uploaded (20)

PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PDF
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 

Web Application Development using PHP Chapter 5

  • 2. PHP Form • A Form is a document that containing black fields, that the user can fill the data or user can select the data. • Casually the data will store in the data base. • When the user fills out the form and clicks the submit button, the form data is sent for processing to a PHP file. • The form data is sent with the HTTP POST or GET method.
  • 3. PHP Form • Example PHP Form using HTML POST method: <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body>
  • 4. PHP Form • To display the submitted data you could simply echo all the variables. • The "welcome.php" looks like this: <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo $_POST["email"]; ?> </body>
  • 5. PHP Form • The same result could also be achieved using the HTTP GET method: <body> <form action="welcome_get.php" method="get"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body>
  • 6. PHP Form • The "welcome_get.php" looks like this: <body> Welcome <?php echo $_GET["name"]; ?><br> Your email address is: <?php echo $_GET["email"]; ?> </body>
  • 7. GET vs. POST • Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3, ...)). • This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user. • $_GET is an array of variables passed to the current script via the URL parameters. • $_POST is an array of variables passed to the current script via the HTTP POST method.
  • 8. GET vs. POST • Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). • GET also has limits on the amount of information to send. • The limitation is about 2000 characters. • GET may be used for sending non-sensitive data.
  • 9. GET vs. POST • Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request) and has no limits on the amount of information to send. • POST supports advanced functionality such as support for multi-part binary input while uploading files to server.
  • 10. Form Validation • Validation means check the input submitted by the user. • Proper validation of form data is important to protect your form from hackers and spammers! • There are two types of validation are available in PHP. • They are as follows: • Client-Side Validation − Validation is performed on the client machine web browsers. • Server Side Validation − After submitted by data, The data has sent to a server and perform validation checks in server machine.
  • 11. Example • Below code shows validation of URL: • Below code shows validation of Email address $website = input($_POST["site"]); if (!preg_match("/b(?:(?:https?|ftp)://|www.)[-a-z0- 9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } $email = input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid format and please re-enter valid email"; }
  • 12. Example • The code below shows a simple way to check if the name field only contains letters and whitespace. • If the value of the name field is not valid, then store an error message: $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } preg_match – this function is used to perform a pattern match on a string. It returns true if a match is found and false if a match is not found.
  • 13. Example • In the code below, if the e-mail address is not well-formed, then store an error message: $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; }