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
PPT
Php forms
PDF
PHP Making Web Forms
PDF
Making web forms using php
PPTX
Form Handling using PHP
PPTX
PPTX
PHP Form Validation Technique
PPTX
Url and http
GET and POST in PHP
Php forms
PHP Making Web Forms
Making web forms using php
Form Handling using PHP
PHP Form Validation Technique
Url and http

What's hot (13)

PDF
Le Wagon - Web 101
PPTX
uptu web technology unit 2 html
PDF
Understanding the Web through HTTP
PPTX
SCWCD : The web client model
PPTX
PPT
Get_vs_Post
PPTX
Get and post methods in php - phpgurukul
ODP
Form Processing In Php
PPTX
Hypertext Transfer Protocol
PDF
Imec tcbl single_sign_on_extra
PPTX
Http and its Applications
Le Wagon - Web 101
uptu web technology unit 2 html
Understanding the Web through HTTP
SCWCD : The web client model
Get_vs_Post
Get and post methods in php - phpgurukul
Form Processing In Php
Hypertext Transfer Protocol
Imec tcbl single_sign_on_extra
Http and its Applications
Ad

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

PPTX
forms.pptx
PPTX
2-Chapter Edit.pptx debret tabour university
PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
PPTX
Working with data.pptx
DOCX
Php forms and validations by naveen kumar veligeti
PPTX
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
PDF
web2_lec6.pdf
PPT
PHP - Introduction to PHP Forms
PPT
Lecture7 form processing by okello erick
PDF
Form handling in php
PPTX
PHP 2
PDF
Web app development_php_07
PPTX
hgoeisgiubsuigvbigbisbrgiusrbgibigbibbbb
PPTX
Web Development
PDF
Introduction to php web programming - get and post
PDF
Web Development Course: PHP lecture 2
PDF
PHP-Part4
PPTX
Working with Data and built-in functions of PHP
PPTX
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
PPTX
Web Techniques like Cookies and Sessions
forms.pptx
2-Chapter Edit.pptx debret tabour university
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
Working with data.pptx
Php forms and validations by naveen kumar veligeti
Unit - III.pptxbgffhjxfjdfjfgjnsnsnshdhsjsksjsjsjsjsjsjsjsjsldksk
web2_lec6.pdf
PHP - Introduction to PHP Forms
Lecture7 form processing by okello erick
Form handling in php
PHP 2
Web app development_php_07
hgoeisgiubsuigvbigbisbrgiusrbgibigbibbbb
Web Development
Introduction to php web programming - get and post
Web Development Course: PHP lecture 2
PHP-Part4
Working with Data and built-in functions of PHP
WorkingwithFormsinPHPpptx__2024_10_17_19_07_07 2.pptx
Web Techniques like Cookies and Sessions
Ad

More from Mohd Harris Ahmad Jaal (20)

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

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
O7-L3 Supply Chain Operations - ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Classroom Observation Tools for Teachers
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Insiders guide to clinical Medicine.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
01-Introduction-to-Information-Management.pdf
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES

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"; }