SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Welcome to php
Introduction
Email: sales@kerneltraining.com
Call us: +91 8099776681
www.kerneltraining.com/php
Forms
(Getting data from users)
www.kerneltraining.com/php
Forms: how they work
 We need to know..
1. How forms work.
2. How to write forms in HTML.
3. How to access the data in PHP.
HTML Forum
 The form is enclosed in form tags..
<form action=“path/to/submit/page”
method=“get”>
<!–- form contents -->
</form>
www.kerneltraining.com/php
Form attributes
action=“…” is the page that the form should
submit its data to.
method=“…” is the method by which the form data
is submitted. The option are either get or post. If
the method is get the data is passed in the url string,
if the method is post it is passed as a separate file.
www.kerneltraining.com/php
Form fields: text input
Use a text input within form tags for a single
line freeform text input.
<label for=“fn">First Name</label>
<input type="text"
name="firstname"
id=“fn"
size="20"/>
www.kerneltraining.com/php
Form attributes for text
name=“…” is the name of the field. You will
use this name in PHP to access the data.
id=“…” is label reference string – this should
be the same as that referenced in the <label>
tag.
size=“…” is the length of the displayed text
box (number of characters).
www.kerneltraining.com/php
Form fields: password input
 Use a starred text input for passwords.
<label for=“pw">Password</label>
<input type=“password"
name=“passwd"
id=“pw"
size="20"/>
www.kerneltraining.com/php
www.kerneltraining.com/php
Form fields: text area
If you need more than 1 line to enter data, use a
textarea.
<label for="desc">Description</label>
<textarea name=“description”
id=“desc“
rows=“10” cols=“30”>
Default text goes here…
</textarea>
Form fields: text area
name=“…” is the name of the field. You will use this
name in PHP to access the data.
id=“…” is label reference string – this should be the
same as that referenced in the <label> tag.
rows=“…” cols=“..” is the size of the displayed
text box.
www.kerneltraining.com/php
www.kerneltraining.com/php
Form fields: drop down
<label for="tn">Where do you
live?</label>
<select name="town" id="tn">
<option value="swindon">Swindon</option>
<option value="london”
selected="selected">London</option>
<option value=“bristol">Bristol</option>
</select>
www.kerneltraining.com/php
Form fields: drop down
 name=“…” is the name of the field.
 id=“…” is label reference string.
 <option value=“…” is the actual data sent back
to PHP if the option is selected.
 <option>…</option> is the value displayed to
the user.
 selected=“selected” this option is selected by
default.
www.kerneltraining.com/php
Form fields: radio buttons
<input type="radio"
name="age"
id="u30“
checked=“checked”
value="Under30" />
<label for="u30">Under 30</label>
<br />
<input type="radio"
name="age"
id="thirty40"
value="30to40" />
<label for="thirty40">30 to
40</label>
www.kerneltraining.com/php
Form fields: radio buttons
name=“…” is the name of the field. All radio boxes
with the same name are grouped with only one
selectable at a time.
id=“…” is label reference string.
value=“…” is the actual data sent back to PHP if the
option is selected.
checked=“checked” this option is selected by
default.
www.kerneltraining.com/php
Form fields: check boxes
What colours do you like?<br />
<input type="checkbox"
name="colour[]"
id="r"
checked="checked"
value="red" />
<label for="r">Red</label>
<br />
<input type="checkbox"
name="colour[]"
id="b"
value="blue" />
<label for="b">Blue</label>
www.kerneltraining.com/php
Form fields: check boxes
name=“…” is the name of the field. Multiple
checkboxes can be selected, so if the button are given
the same name, they will overwrite previous values.
The exception is if the name is given with square
brackets – an array is returned to PHP.
id=“…” is label reference string.
value=“…” is the actual data sent back to PHP if the
option is selected.
checked=“checked” this option is selected by
default.
www.kerneltraining.com/php
Hidden Fields
<input type="hidden"
name="hidden_value"
value="My Hidden Value" />
 name=“…” is the name of the field.
 value=“…” is the actual data sent back to PHP.
www.kerneltraining.com/php
Submit button..
 A submit button for the form can be created
with the code:
<input type="submit"
name="submit"
value="Submit" />
www.kerneltraining.com/php
Fieldset
 In HTML 1.0, all inputs must be grouped within the form
into fieldsets. These represent logical divisions through
larger forms. For short forms, all inputs are contained in a
single fieldset.
<form>
<fieldset>
<input … />
<input … />
</fieldset>
<fieldset>
<input … />
<input … />
</fieldset>
</form>
www.kerneltraining.com/php
How to access data ?
 The variables are available in two super global arrays
created by PHP called $_POST and $_GET.
 We can access form data by using $_REQUEST also. This
variable access data from both methods either GET or
POST
www.kerneltraining.com/php
Access data
 Access submitted data in the relevant array for the
submission type, using the input name as a key.
<form action=“path/to/submit/page”
method=“get”>
<input type=“text” name=“email”>
</form>
$email = $_GET[‘email’];
www.kerneltraining.com/php
Is it submitted?
We also need to check before accessing data to
see if the data is submitted, use isset() function.
if (isset($_POST[‘username’])) {
// perform validation
}
www.kerneltraining.com/php
What is form validation?
 validation: ensuring that form's values are correct
 some types of validation:
 preventing blank values (email address)
 ensuring the type of values
 integer, real number, currency, phone number,
Social Security number, postal
 address, email address, date, credit card number, ...
 ensuring the format and range of values (ZIP code
must be a 5-digit integer)
 ensuring that values fit together (user types email
twice, and the two must match)
www.kerneltraining.com/php
A real Form that uses validation
www.kerneltraining.com/php
Client vs. server-side validation
 Validation can be performed:
 client-side (before the form is submitted)
 This can be done by using either
javascript or jquery
 server-side (in PHP code, after the form is
submitted)
 needed for truly secure validation, but
slower
www.kerneltraining.com/php
An example form to be validated
//form.php
<form action=“process.php" method="get">
<div>
Name: <input type=“text” name=“first_name" /> <br />
Username: <input type=“text” name=“username" size="20” />
<br />
Password: <input type=“password” name=" password "
size="5" /> <br />
<input type="submit" name=“submit” value=“Submit”/>
</div>
</form> HTML
 Let's validate this form's data on the server...
www.kerneltraining.com/php
Basic server-side validation code
//process.php
$name= $_GET[“first_name"];
$username= GET[“username"];
$password= $_GET[“password"];
if (isset($username) || strlen($username)< 4) {
?>
<h2>Error, invalid Username entered.</h2>
<?php
}
?> PHP
 basic idea: examine parameter values, and if they are bad,
show an error message and abort
Questions?
www.kerneltraining.com/php
THANK YOU
for attending Lessons
of php
www.kerneltraining.com/php
Email: sales@kerneltraining.com
Call us: +91 8099776681

Weitere ähnliche Inhalte

Andere mochten auch

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorialice27
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting languageElmer Concepcion Jr.
 
Pemrograman web dengan php my sql
Pemrograman web dengan php my sqlPemrograman web dengan php my sql
Pemrograman web dengan php my sqlanarkonam
 
Pemrograman Web with PHP MySQL
Pemrograman Web with PHP MySQLPemrograman Web with PHP MySQL
Pemrograman Web with PHP MySQLdjokotingkir999
 
PHP MySQL database connections
PHP MySQL database connectionsPHP MySQL database connections
PHP MySQL database connectionsayman diab
 
How to make Android apps secure: dos and don’ts
How to make Android apps secure: dos and don’tsHow to make Android apps secure: dos and don’ts
How to make Android apps secure: dos and don’tsNowSecure
 
PHP - Beginner's Workshop
PHP - Beginner's WorkshopPHP - Beginner's Workshop
PHP - Beginner's WorkshopRafael Pinto
 
Modul praktikum javascript
Modul praktikum javascriptModul praktikum javascript
Modul praktikum javascripthardyta
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlAimal Miakhel
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)Arjun Shanka
 

Andere mochten auch (19)

Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php mysq l - siapa - takut
Php mysq l - siapa - takutPhp mysq l - siapa - takut
Php mysq l - siapa - takut
 
Pemrograman web dengan php my sql
Pemrograman web dengan php my sqlPemrograman web dengan php my sql
Pemrograman web dengan php my sql
 
Pemrograman Web with PHP MySQL
Pemrograman Web with PHP MySQLPemrograman Web with PHP MySQL
Pemrograman Web with PHP MySQL
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
PHP MySQL database connections
PHP MySQL database connectionsPHP MySQL database connections
PHP MySQL database connections
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
How to make Android apps secure: dos and don’ts
How to make Android apps secure: dos and don’tsHow to make Android apps secure: dos and don’ts
How to make Android apps secure: dos and don’ts
 
PHP - Beginner's Workshop
PHP - Beginner's WorkshopPHP - Beginner's Workshop
PHP - Beginner's Workshop
 
Modul praktikum javascript
Modul praktikum javascriptModul praktikum javascript
Modul praktikum javascript
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 

Kürzlich hochgeladen

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
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
 
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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Kürzlich hochgeladen (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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 ...
 
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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Php Tutorial | Introduction Demo | Basics

  • 1. Welcome to php Introduction Email: sales@kerneltraining.com Call us: +91 8099776681
  • 3. www.kerneltraining.com/php Forms: how they work  We need to know.. 1. How forms work. 2. How to write forms in HTML. 3. How to access the data in PHP.
  • 4. HTML Forum  The form is enclosed in form tags.. <form action=“path/to/submit/page” method=“get”> <!–- form contents --> </form> www.kerneltraining.com/php
  • 5. Form attributes action=“…” is the page that the form should submit its data to. method=“…” is the method by which the form data is submitted. The option are either get or post. If the method is get the data is passed in the url string, if the method is post it is passed as a separate file. www.kerneltraining.com/php
  • 6. Form fields: text input Use a text input within form tags for a single line freeform text input. <label for=“fn">First Name</label> <input type="text" name="firstname" id=“fn" size="20"/> www.kerneltraining.com/php
  • 7. Form attributes for text name=“…” is the name of the field. You will use this name in PHP to access the data. id=“…” is label reference string – this should be the same as that referenced in the <label> tag. size=“…” is the length of the displayed text box (number of characters). www.kerneltraining.com/php
  • 8. Form fields: password input  Use a starred text input for passwords. <label for=“pw">Password</label> <input type=“password" name=“passwd" id=“pw" size="20"/> www.kerneltraining.com/php
  • 9. www.kerneltraining.com/php Form fields: text area If you need more than 1 line to enter data, use a textarea. <label for="desc">Description</label> <textarea name=“description” id=“desc“ rows=“10” cols=“30”> Default text goes here… </textarea>
  • 10. Form fields: text area name=“…” is the name of the field. You will use this name in PHP to access the data. id=“…” is label reference string – this should be the same as that referenced in the <label> tag. rows=“…” cols=“..” is the size of the displayed text box. www.kerneltraining.com/php
  • 11. www.kerneltraining.com/php Form fields: drop down <label for="tn">Where do you live?</label> <select name="town" id="tn"> <option value="swindon">Swindon</option> <option value="london” selected="selected">London</option> <option value=“bristol">Bristol</option> </select>
  • 12. www.kerneltraining.com/php Form fields: drop down  name=“…” is the name of the field.  id=“…” is label reference string.  <option value=“…” is the actual data sent back to PHP if the option is selected.  <option>…</option> is the value displayed to the user.  selected=“selected” this option is selected by default.
  • 13. www.kerneltraining.com/php Form fields: radio buttons <input type="radio" name="age" id="u30“ checked=“checked” value="Under30" /> <label for="u30">Under 30</label> <br /> <input type="radio" name="age" id="thirty40" value="30to40" /> <label for="thirty40">30 to 40</label>
  • 14. www.kerneltraining.com/php Form fields: radio buttons name=“…” is the name of the field. All radio boxes with the same name are grouped with only one selectable at a time. id=“…” is label reference string. value=“…” is the actual data sent back to PHP if the option is selected. checked=“checked” this option is selected by default.
  • 15. www.kerneltraining.com/php Form fields: check boxes What colours do you like?<br /> <input type="checkbox" name="colour[]" id="r" checked="checked" value="red" /> <label for="r">Red</label> <br /> <input type="checkbox" name="colour[]" id="b" value="blue" /> <label for="b">Blue</label>
  • 16. www.kerneltraining.com/php Form fields: check boxes name=“…” is the name of the field. Multiple checkboxes can be selected, so if the button are given the same name, they will overwrite previous values. The exception is if the name is given with square brackets – an array is returned to PHP. id=“…” is label reference string. value=“…” is the actual data sent back to PHP if the option is selected. checked=“checked” this option is selected by default.
  • 17. www.kerneltraining.com/php Hidden Fields <input type="hidden" name="hidden_value" value="My Hidden Value" />  name=“…” is the name of the field.  value=“…” is the actual data sent back to PHP.
  • 18. www.kerneltraining.com/php Submit button..  A submit button for the form can be created with the code: <input type="submit" name="submit" value="Submit" />
  • 19. www.kerneltraining.com/php Fieldset  In HTML 1.0, all inputs must be grouped within the form into fieldsets. These represent logical divisions through larger forms. For short forms, all inputs are contained in a single fieldset. <form> <fieldset> <input … /> <input … /> </fieldset> <fieldset> <input … /> <input … /> </fieldset> </form>
  • 20. www.kerneltraining.com/php How to access data ?  The variables are available in two super global arrays created by PHP called $_POST and $_GET.  We can access form data by using $_REQUEST also. This variable access data from both methods either GET or POST
  • 21. www.kerneltraining.com/php Access data  Access submitted data in the relevant array for the submission type, using the input name as a key. <form action=“path/to/submit/page” method=“get”> <input type=“text” name=“email”> </form> $email = $_GET[‘email’];
  • 22. www.kerneltraining.com/php Is it submitted? We also need to check before accessing data to see if the data is submitted, use isset() function. if (isset($_POST[‘username’])) { // perform validation }
  • 23. www.kerneltraining.com/php What is form validation?  validation: ensuring that form's values are correct  some types of validation:  preventing blank values (email address)  ensuring the type of values  integer, real number, currency, phone number, Social Security number, postal  address, email address, date, credit card number, ...  ensuring the format and range of values (ZIP code must be a 5-digit integer)  ensuring that values fit together (user types email twice, and the two must match)
  • 25. www.kerneltraining.com/php Client vs. server-side validation  Validation can be performed:  client-side (before the form is submitted)  This can be done by using either javascript or jquery  server-side (in PHP code, after the form is submitted)  needed for truly secure validation, but slower
  • 26. www.kerneltraining.com/php An example form to be validated //form.php <form action=“process.php" method="get"> <div> Name: <input type=“text” name=“first_name" /> <br /> Username: <input type=“text” name=“username" size="20” /> <br /> Password: <input type=“password” name=" password " size="5" /> <br /> <input type="submit" name=“submit” value=“Submit”/> </div> </form> HTML  Let's validate this form's data on the server...
  • 27. www.kerneltraining.com/php Basic server-side validation code //process.php $name= $_GET[“first_name"]; $username= GET[“username"]; $password= $_GET[“password"]; if (isset($username) || strlen($username)< 4) { ?> <h2>Error, invalid Username entered.</h2> <?php } ?> PHP  basic idea: examine parameter values, and if they are bad, show an error message and abort
  • 29. THANK YOU for attending Lessons of php www.kerneltraining.com/php Email: sales@kerneltraining.com Call us: +91 8099776681