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

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Kürzlich hochgeladen (20)

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

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