SlideShare une entreprise Scribd logo
1  sur  18
Working with Forms
Superglobal Variables
• A global variable is any variable declared at the "top level" of a
script—that is, declared outside a function.
• Superglobal variables are arrays built in to PHP.
The $_SERVER Array
• The $_SERVER array contains elements set by your script's context, usually the
server.
<html> <head>
</head><body>
<div>
<?php
If ( ! empty( $_POST['guess'] ) ) {
print "last guess: ".$_POST['guess'];
}
?>
<form method="post" action="<?php print $_SERVER['PHP_SELF']?>">
<p>
Type your guess here: <input type="text" name="guess" />
</p>
</form>
</div>
</body>
</html>
EX:
action="<?php print $_SERVER['PHP_SELF']?>“
action="1.php"
Note the PHP_SELF element in particular. We use it to point forms and links back at their
enclosing scripts.
1.html
2.php
1.html
2.php
Accessing Form Input with User-Defined Arrays
Combining HTML and PHP Code on a Single Page
Using Hidden Fields to Save State
<? print $test;?>
It is equivalent to
<?=$test?>
Redirecting the User
header("Location:congrats.html");
if ( ! headers_sent() )
{
header( "Location: http://www.example.com" );
exit;
}
File Upload Forms and Scripts
• We limited file uploads to 100KB
Ch2(working with forms)
Ch2(working with forms)

Contenu connexe

Tendances

16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravelRazvan Raducanu, PhD
 
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryJAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryZigotto Tecnologia
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)Kana Natsuno
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operatorsKhem Puthea
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filtersiamdangavin
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeYoav Farhi
 
May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014Chad Windnagle
 
WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016
WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016
WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016Jesper van Engelen
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28thChris Adams
 
Introducing thymeleaf
Introducing thymeleafIntroducing thymeleaf
Introducing thymeleafeiryu
 
Simplifying Code: Monster to Elegant in 5 Steps
Simplifying Code: Monster to Elegant in 5 StepsSimplifying Code: Monster to Elegant in 5 Steps
Simplifying Code: Monster to Elegant in 5 Stepstutec
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-KjaerCOMMON Europe
 
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016Matheus Marabesi
 
Powershell function
Powershell functionPowershell function
Powershell functionLearningTech
 

Tendances (20)

16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravel
 
21.search in laravel
21.search in laravel21.search in laravel
21.search in laravel
 
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryJAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
WooCommerce filters
WooCommerce filtersWooCommerce filters
WooCommerce filters
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Modular Angular JS
Modular Angular JSModular Angular JS
Modular Angular JS
 
May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016
WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016
WordCamp Geneva Presentation - Customising WordPress' Admin Panel - 19 Nov. 2016
 
5. CodeIgniter copy1
5. CodeIgniter copy15. CodeIgniter copy1
5. CodeIgniter copy1
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
 
Introducing thymeleaf
Introducing thymeleafIntroducing thymeleaf
Introducing thymeleaf
 
Simplifying Code: Monster to Elegant in 5 Steps
Simplifying Code: Monster to Elegant in 5 StepsSimplifying Code: Monster to Elegant in 5 Steps
Simplifying Code: Monster to Elegant in 5 Steps
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
 
Powershell function
Powershell functionPowershell function
Powershell function
 

En vedette

300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles PorterTXGroundwaterSummit
 
Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Chhom Karath
 
eMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior CentereMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior CenterSnowSugar Video
 
Appendex e
Appendex eAppendex e
Appendex eswavicky
 
PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3melechi
 
Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidarFinal morris esri_nwgis_lidar
Final morris esri_nwgis_lidarEric Morris
 
Setting up a gmail account
Setting up a gmail accountSetting up a gmail account
Setting up a gmail accountkeelyswitzer
 
Groundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterGroundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterTXGroundwaterSummit
 
Chapter 9 Asynchronous Communication
Chapter 9 Asynchronous CommunicationChapter 9 Asynchronous Communication
Chapter 9 Asynchronous CommunicationPatty Ramsey
 
Chapter 7 Multimedia
Chapter 7 MultimediaChapter 7 Multimedia
Chapter 7 MultimediaPatty Ramsey
 
Appendex g
Appendex gAppendex g
Appendex gswavicky
 
Appendex b
Appendex bAppendex b
Appendex bswavicky
 
Appendex a
Appendex aAppendex a
Appendex aswavicky
 
Drought: Looking Back and Planning Ahead, Todd Votteler
Drought: Looking Back and Planning Ahead, Todd VottelerDrought: Looking Back and Planning Ahead, Todd Votteler
Drought: Looking Back and Planning Ahead, Todd VottelerTXGroundwaterSummit
 
Appendex c
Appendex cAppendex c
Appendex cswavicky
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Chhom Karath
 
Chapter 1Into the Internet
Chapter 1Into the InternetChapter 1Into the Internet
Chapter 1Into the InternetPatty Ramsey
 
Application of dual output LiDAR scanning system for power transmission line ...
Application of dual output LiDAR scanning system for power transmission line ...Application of dual output LiDAR scanning system for power transmission line ...
Application of dual output LiDAR scanning system for power transmission line ...Pedro Llorens
 

En vedette (20)

300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter300 Years of Groundwater Management, Charles Porter
300 Years of Groundwater Management, Charles Porter
 
Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)
 
eMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior CentereMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior Center
 
Chapter 5 Input
Chapter 5 InputChapter 5 Input
Chapter 5 Input
 
Emoji International Name Finder
Emoji International Name FinderEmoji International Name Finder
Emoji International Name Finder
 
Appendex e
Appendex eAppendex e
Appendex e
 
PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3
 
Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidarFinal morris esri_nwgis_lidar
Final morris esri_nwgis_lidar
 
Setting up a gmail account
Setting up a gmail accountSetting up a gmail account
Setting up a gmail account
 
Groundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterGroundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan Schuster
 
Chapter 9 Asynchronous Communication
Chapter 9 Asynchronous CommunicationChapter 9 Asynchronous Communication
Chapter 9 Asynchronous Communication
 
Chapter 7 Multimedia
Chapter 7 MultimediaChapter 7 Multimedia
Chapter 7 Multimedia
 
Appendex g
Appendex gAppendex g
Appendex g
 
Appendex b
Appendex bAppendex b
Appendex b
 
Appendex a
Appendex aAppendex a
Appendex a
 
Drought: Looking Back and Planning Ahead, Todd Votteler
Drought: Looking Back and Planning Ahead, Todd VottelerDrought: Looking Back and Planning Ahead, Todd Votteler
Drought: Looking Back and Planning Ahead, Todd Votteler
 
Appendex c
Appendex cAppendex c
Appendex c
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
 
Chapter 1Into the Internet
Chapter 1Into the InternetChapter 1Into the Internet
Chapter 1Into the Internet
 
Application of dual output LiDAR scanning system for power transmission line ...
Application of dual output LiDAR scanning system for power transmission line ...Application of dual output LiDAR scanning system for power transmission line ...
Application of dual output LiDAR scanning system for power transmission line ...
 

Similaire à Ch2(working with forms)

Similaire à Ch2(working with forms) (20)

Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Php
PhpPhp
Php
 
Grok Drupal (7) Theming
Grok Drupal (7) ThemingGrok Drupal (7) Theming
Grok Drupal (7) Theming
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
php 1
php 1php 1
php 1
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
basics of php
 basics of php basics of php
basics of php
 

Plus de Chhom Karath

Plus de Chhom Karath (20)

set1.pdf
set1.pdfset1.pdf
set1.pdf
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
 
Bracket size
Bracket sizeBracket size
Bracket size
 
Couple
CoupleCouple
Couple
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
 
Game1
Game1Game1
Game1
 
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
 
Opus loop
Opus loopOpus loop
Opus loop
 
V bend
V bendV bend
V bend
 
Closing loop
Closing loopClosing loop
Closing loop
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
 

Dernier

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Dernier (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Ch2(working with forms)

Notes de l'éditeur

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Listing 10.1 Looping through the $_SERVER array</title> </head> <body> <div> <?php foreach ( $_SERVER as $key=>$value ) { print "\$_SERVER[\"$key\"] == $value<br/>"; } ?> </div> </body> </html>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Register my site:</title> </head> <body> <h1>Register my site:</h1> <p>To register, please fill in your details below and click Send Details.</p> <form action="register.php" method="post"> <table> <tr><td><label for="firstName">First name:</label></td><td><input type="text" name="firstName" value="" /></td></tr> <tr><td><label for="lastName">Last name</label></td><td><input type="text" name="lastName" value="" /></td></tr> <tr><td><label for="password1">Choose a password</label></td><td><input type="password" name="password1" value="" /></td></tr> <tr><td><label for="password2">Retype password</label></td><td><input type="password" name="password2" value="" /></td></tr> <tr><td><label for="genderMale">Are you male...</label></td><td><input type="radio" name="gender" value="M" /></td></tr> <tr><td><label for="genderFemale">...or female?</label></td><td><input type="radio" name="gender" value="F" /></td></tr> <tr><td> <label for="country">What's your country?</label></td><td><select name="country" size="1"> <option value="Cambodia">Cambodia</option> <option value="USA">USA</option> <option value="Japan">Japan</option> <option value="Other">Other</option> </select></td></tr> <tr><td><label for="newsletter">Are you married? </label></td><td> <input type="checkbox" name="marry" value="yes" /></td></tr> <tr><td><label for="comments">Any comments?</label></td><td><textarea name="comments" rows="4" cols="50"> </textarea></td></tr> <tr><td><input type="submit" name="submitButton" id="submitButton" value="Send Details" /></td><td><input type="reset" name="resetButton" value="Reset Form" style="margin-right: 20px;" /></td></tr> </form> </body> </html> Register.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Thank You</title> </head> <body> <h1>Thank You</h1> <p>Thank you for registering. Here is the information you submitted:</p> <table border=1 cellspacing="0"> <tr><td>First name</td><td><?php echo $_POST["firstName"]?></td></tr> <tr><td>Last name</td><td><?php echo $_POST["lastName"]?></td></tr> <tr><td>Password</td><td><?php echo $_POST["password1"]?></td></tr> <tr><td>Retyped password</td><td><?php echo $_POST["password2"]?></td></tr> <tr><td>Gender</td><td><?php echo $_POST["gender"]?></td></tr> <tr><td>Country</td><td><?php echo $_POST["country"]?></td> <tr><td>Are you married?</td><td><?php echo $_POST["marry"]?></td> <tr><td>Comments</td><td><?php echo $_POST["comments"]?></td> </table> </body> </html>
  3. <?php if(isset($_POST['bt'])) { $data=$_POST['txt1']; if( !isset( $_POST['txt1'] ) or !$_POST['txt1']) echo "please enter data"; else echo "thanks"; } else $data=""; ?> <form method="post" action=""> <input type="text" name="txt1" value="<?php echo $data; ?>"></input> <input type="submit" name="bt"></input> </form> // or <?php if(isset($_POST['bt'])) { $data=$_POST['txt1']; if( !empty( $_POST['txt1'] )) echo "please enter data"; else echo "thanks"; } else $data=""; ?> <form method="post" action=""> <input type="text" name="txt1" value="<?php echo $data; ?>"></input> <input type="submit" name="bt"></input> </form>
  4. <html> <head><title></title> </head> <body> <form method="post" action="5.php"> <table> <tr><td>Value 1:</td><td><input type="text" name="txtV1" /></td></tr> <tr><td>Value 2:</td><td><input type="text" name="txtV2" /></td></tr> <tr><td colspan=2><input type="submit" name="btSum" value=" + " /><input type="submit" name="btMinus" value=" - " /> <input type="submit" name="btMult" value=" * " /><input type="submit" name="btDiv" value=" / " /></td></tr> </table> </form> <?php if ( ! empty( $_POST['txtV1'] ) && !empty($_POST['txtV2'] )) { if(isset( $_POST['btSum'] )) { print "The Result is " . $_POST['txtV1'] . "+" . $_POST['txtV2'] . "=" . ($_POST['txtV1']+$_POST['txtV2'] ). "<br/>"; } else if(isset($_POST['btMinus'])) { print "The Result is " . $_POST['txtV1'] . "-" . $_POST['txtV2'] . "=" . ($_POST['txtV1']-$_POST['txtV2'] ). "<br/>"; } else if(isset($_POST['btMult'])) { print "The Result is " . $_POST['txtV1'] . "*" . $_POST['txtV2'] . "=" . ($_POST['txtV1']*$_POST['txtV2'] ). "<br/>"; } else if(isset($_POST['btDiv'])) { print "The Result is " . $_POST['txtV1'] . "/" . $_POST['txtV2'] . "=" . ($_POST['txtV1']/$_POST['txtV2'] ). "<br/>"; } } ?> </body> </html>
  5. 1.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Listing 10.2 A Simple HTML Form</title> </head> <body> <div> <form action="2.php" method="get"> <table> <tr><td>User name:</td><td> <input type="text" name="user"/></td> <tr><td>Gender:</td><td><select name="sex"> <option value="Male">Male</option> <option value="Female">Female</option> </select></td></tr> <tr><td>Address:</td><td><textarea name="address" rows="5" cols="40"></textarea></td></tr> <tr><td><input type="submit" value="hit it!" /></td><td><input type="reset" value="RESET"></td></tr> </form> </div> </body> </html> 2.Php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Listing 10.3 Reading Input from the Form in Listing 10.2</title> </head> <body> <div> <?php if($_GET['user']=='') print "<font color='red'>Please enter user name!</font>"; else if($_GET['address']=='') print "<font color='red'>Please enter address</font>"; else { print "<table>"; print "<tr><td>Welcome to:</td><td>" .$_GET['user']. "</td></tr>"; print "<tr><td>Your address is: <td/><td>" . $_GET['address'] . "</td></tr>"; print "<tr><td>Sex: <td/><td>" . $_GET['sex'] . "</td></tr>"; print "</table>"; } ?> </div> </body> </html>
  6. 1.Html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title></title> <script language="javascript"> function test() { if(document.frm.user.value=="") { alert("Please, enter your name"); } else if(document.frm.address.value=="") alert("Please, enter address "); } </script> </head> <body> <form action="2.php" method="post" name="frm"> <table align="center"> <tr><td colspan=2 align=center bgcolor=red><b>Product Selected List</b></td></tr> <tr><td>Name:</td><td><input type="text" name="user" /></td></tr> <tr><td>Address:</td><td><textarea name="address" rows="5" cols="40"></textarea></td></tr> <tr><td>Product</td><td><select name="products[]" multiple="multiple"> <option>IPhone</option> <option>Icom</option> <option>Icream</option> <option>Ilove</option> </select> </td></tr> <tr><td><input type=button value="Test" onclick="test()"><input type="submit" value="SUBMIT" /></td><td><input type="reset"></td></tr> </table> </form> </body> </html> 2.Php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> </head> <body> <div> <?php print "Name:" .$_POST['user']. "</b><br/>\n"; print "Your address is:<br/><b>" . $_POST['address'] . "</b><br/>\n"; if ( is_array( $_POST['products'] ) ) { print "<p>Your product choices are:</p>\n"; print "<ul>\n"; foreach ( $_POST['products'] as $value ) { print "<li>$value</li>\n"; } print "</ul>"; } ?> </div> </body> </html>
  7. <?php $num_to_guess = 42; $message = ""; if ( ! isset( $_POST['guess'] ) ) { $message = "Welcome to the guessing machine!"; } else if ( $_POST['guess'] > $num_to_guess ) { $message = $_POST['guess']." is too big! Try a smaller number"; } else if ( $_POST['guess'] < $num_to_guess ) { $message = $_POST['guess']." is too small! Try a larger number"; } else { // must be equivalent $message = "Well done!"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Listing 10.7 A PHP Number Guessing Script</title> </head> <body> <h1> <?php print $message ?> </h1> <form method="post" action="<?php print $_SERVER['PHP_SELF']?>"> <p> Type your guess here: <input type="text" name="guess" /> <input type="submit" value="submit" /> </p> </form> </body> </html> </body> </html>
  8. <?php if(isset($_POST['btSubmit'])) { if(empty($_POST['txtNumber'])) { $smg="Please enter number 1-2 !"; $num=$_POST['txtNumber']; $result=""; $st=""; } else{ $smg=""; $num=$_POST['txtNumber']; $st=""; $result=rand(1,2); if($_POST['txtNumber']==$result) { $st="You win!"; } else $st="You loss!"; } } else { $smg=""; $result=""; $st=""; $num=""; } ?> <html> <head><title></title></head> <body> <form method="post" action=""> <table> <tr><td><label for="txtNumber">Input data from 1-2:</label></td><td><input type="text" name="txtNumber" value="<?php print $num; ?>"></input></td></tr> <tr><td>Result:</td><td><?php print $result . "\n" . $st; ?></td></tr> <tr><td><input type="submit" name="btSubmit" value="Click ME!"></td><td><input type="reset" value="clear"></input></tr> <tr><td colspan=2"><?php print "<p style='background=red'>" . $smg . "</p>"; ?></td></tr> </table> </form> </body> </html>
  9. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> <?php $firstName=""; $fullName=""; $midName=""; $lastName=""; if(!empty($_POST['txtFullName'])) { if(isset($_POST['btSplit'])) { $fullName = $_POST['txtFullName']; $name_array = explode (" ",$fullName); if( count($name_array)>3) { $firstName=$name_array[0]; $i=1; for(;$i<count($name_array)-1;$i++) { $midName .=$name_array[$i] . " "; } $lastName=$name_array[$i]; } else if(count($name_array)==3) { $firstName=$name_array[0]; $midName=$name_array[1]; $lastName=$name_array[2]; } else if(count($name_array)==2) { $firstName=$name_array[0]; $midName="No mid name"; $lastName=$name_array[1]; } } else if(isset($_POST['btClear'])) { $fullName = ""; $firstName=""; $midName=""; $lastName=""; } } ?> </head> <body> <form name="frm" method=post action="4.php"> <table align="center" > <tr><td colspan="2">Fullname=First name + Mid name + Last name</td></tr> <tr><td>Full name:</td><td><input type=text name="txtFullName" value="<?php print $fullName; ?>"/></td></tr> <tr><td>First name:</td><td><input type=text name="txtFirstName" value="<?php print $firstName; ?>"/></td></tr> <tr><td>Mid name:</td><td><input type=text name="txtMidName" value="<?php print $midName; ?>"/></td></tr> <tr><td>Last name:</td><td><input type=text name="txtLastName" value="<?php print $lastName; ?>"/></td></tr> <tr><td><input type=submit name="btSplit" value="Split"></td><td><input type="submit" name="btClear" value="Clear"></td></tr> </table> </form> </body> </html>
  10. <html> <head> <title>Value 1</title> <?php $v1Note=""; $v2Note=""; $v3Note=""; $v4Note=""; $v1=""; $v2=""; $v3=""; $v4=""; $min=""; $max=""; if(!empty($_POST['btOK'])) { $v1=$_POST['txtValue1']; $v2=$_POST['txtValue2']; $v3=$_POST['txtValue3']; $v4=$_POST['txtValue4']; if ($_POST['txtValue1'] =="" ) { $v1Note="Please, enter value 1"; } else if($_POST['txtValue2']=="") { $v2Note="Please, enter value 2"; } else if(empty($_POST['txtValue3'])) { $v3Note="Please, enter value 3"; } else if(empty($_POST['txtValue4'])) { $v4Note="Please, enter value 4"; } else { $min=$v1; if($min>$v2) $min=$v2; if($min>$v3) $min=$v3; if($min>$v4) $min=$v4; $max=$v1; if($max<$v2) $max=$v2; if($max<$v3) $max=$v3; if($max<$v4) $max=$v4; } } ?> <script language="javaScript"> function clearV() { document.frm.txtValue1.value=""; document.frm.txtValue2.value=""; document.frm.txtValue3.value=""; document.frm.txtValue4.value=""; document.frm.txtMin.value=""; document.frm.txtMax.value=""; } </script> </head> <body> <form method="post" action="<?php print $_SERVER['PHP_SELF']?>" name="frm"> <table> <tr><td>Value 1:</td><td><input type="text" name="txtValue1" value="<?php print $v1; ?>"/></td><td><?php print $v1Note; ?></td> </tr> <tr><td>Value 2:</td><td><input type="text" name="txtValue2" value="<?php print $v2; ?>"/></td><td><?php print $v2Note; ?></td> </tr> <tr><td>Value 3:</td><td><input type="text" name="txtValue3" value="<?php print $v3; ?>"/></td><td><?php print $v3Note; ?></td> </tr> <tr><td>Value 4:</td><td><input type="text" name="txtValue4" value="<?php print $v4; ?>"/></td><td><?php print $v4Note; ?></td> </tr> <tr><td>Minimum:</td><td ><input type="text" name="txtMin" value="<?php print $min ?>"></td></tr> <tr><td>Maximum:</td><td><input type="text" name="txtMax" value="<?php print $max; ?>"></td></tr> <tr><td><input type="submit" value="OK" name="btOK"></td><td><input type="button" value="clear" onclick="clearV()"></td></tr> </table> </form> </body> </html>
  11. <?php $num_to_guess = 42; $message = ""; $guess =(int) $_POST['guess']; $num_tries = (int) $_POST['num_tries']; $num_tries++; if ( ! isset( $_POST['guess'] ) ) { $message = "Welcome to the guessing machine!"; } else if ( $_POST['guess'] > $num_to_guess ) { $message = $_POST['guess']." is too big! Try a smaller number"; } else if ( $_POST['guess'] < $num_to_guess ) { $message = $_POST['guess']." is too small! Try a larger number"; } else { header("Location:congrats.html"); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Number Guessing Script</title> </head> <body> <div> <h1><?php print $message ?></h1> Guess number: <?php print $num_tries?><br/> <form method="post" action="<?php print $_SERVER['PHP_SELF']?>"> <p> <input type="hidden" name="num_tries" value="<?php print $num_tries?>" /> Type your guess here: <input type="text" name="guess" value="<?php print $guess?>"/> </p> </form> </div> </body> </html>
  12. <html><head><title></title> </head> <body> <form action="4.php" method="post"> <table> <tr><td>Email Address:</td><td><input type="text" name="email" size="20" maxlength="40" value="" /></td></tr> <tr><td colspan=2><input type="submit" name = "submit" value="Go!" /></td> </form> </body> </html> <?php if (isset($_POST['submit'])) { if(!empty($_POST['email'])) { $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+) *(\.[a-z]{2,6})$"; if (eregi($regexp, $_POST['email'])==1) { print "The address ". $_POST['email']. " is valid!"; } else echo "The address <strong>".$_POST['email']."</strong> is invalid!"; } } ?> //Mail <html> <head><title></title> <?php if(isset($_POST['btSubmit'])) { $at=false; $dot=false; $mail=$_POST['txtMail']; for($i=0;$i<strlen($mail);$i++) { if($mail[$i]=="@") { $at=true; } if($mail[$i]==".") { $dot=true; } } if($at==true && $dot==true) { print "It is mail na, thanks, successfully."; } else { print "It is not mail te!"; } } ?> </head> <form method="post" action=""> <label for="txtMail">E-Mail: </label><input type="text" name="txtMail" value="<?php print $_POST['txtMail']; ?>"></input> <input type="submit" name="btSubmit" value="OK"></input> </form> </html>
  13. <?php if ( isset( $_POST["submitVisit"] ) ) { switch ( $_POST["site"] ) { case "google": header( "Location: http://www.google.com/" ); break; case "facebook": header( "Location: http://facebook.com/" ); break; case "camhr": header( "Location: http://www.camhr.com/" ); break; } } else { displayForm(); } function displayForm() { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Website</title> </head> <body> <h1>Website goto:</h1> <form action="" method="post"> <label for="site">Go to website:</label> <select name="site" > <option value="google">www.google.com</option> <option value="facebook">www.facebook.com</option> <option value="camhr">www.camhr.com</option> </select> <br/> <input type="submit" name="submitVisit" value="Visit" /> </form> <?php } ?> </body> </html>
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Listing 10.12 A File Upload Script</title> </head> <body> <div> <?php if ( isset( $_FILES['fupload'] ) ) { print "name: ". $_FILES['fupload']['name'] ."<br />"; print "size: ". $_FILES['fupload']['size'] ." bytes<br />"; print "temp name: ".$_FILES['fupload']['tmp_name'] ."<br />"; print "type: ". $_FILES['fupload']['type'] ."<br />"; print "error: ". $_FILES['fupload']['error'] ."<br />"; $source = $_FILES['fupload']['tmp_name']; $target = "upload/".$_FILES['fupload']['name']; move_uploaded_file( $source, $target ); $size = getImageSize( $target ); $imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" "; $imgstr .= "src=\"$target\" alt=\"uploaded image\" /></p>"; print $imgstr; } ?> </div> <form enctype="multipart/form-data" action="<?php print $_SERVER['PHP_SELF']?>" method="post"> <p> <input type="file" name="fupload" /><br/> <input type="submit" value="upload!" /> </p> </form> </body> </html>
  15. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Register my SITE</title> <style type="text/css"> .error { background: #d33; color: white; } </style> </head> <body> <?php if ( isset( $_POST["submitButton"] ) ) { processForm(); } else { displayForm( array() ); } function validateField( $fieldName, $missingFields ) { if ( in_array( $fieldName, $missingFields ) ) { echo ' class="error"'; } } function setValue( $fieldName ) { if ( isset( $_POST[$fieldName] ) ) { echo $_POST[$fieldName]; } } function setChecked( $fieldName, $fieldValue ) { if ( isset( $_POST[$fieldName] ) and $_POST[$fieldName] == $fieldValue ) { echo ' checked="checked"'; } } function setSelected( $fieldName, $fieldValue ) { if ( isset( $_POST[$fieldName] ) and $_POST[$fieldName] == $fieldValue ) { echo ' selected="selected"'; } } function processForm() { $requiredFields = array( "firstName", "lastName", "password1", "password2", "gender" ); $missingFields = array(); foreach ( $requiredFields as $requiredField ) { if ( !isset( $_POST[$requiredField] ) or !$_POST[$requiredField] ) { $missingFields[] = $requiredField; } } if ( $missingFields ) { displayForm( $missingFields ); } else { displayThanks(); } } function displayForm( $missingFields ) { ?> <?php if ( $missingFields ) { ?> <p class="error">There were some problems with the form you submitted. Please complete the fields highlighted below and click Send Details to resend the form.</p> <?php } else { ?> <p>Thanks for choosing to join The Widget Club. To register, please fill in your details below and click Send Details. Fields marked with an asterisk (*) are required.</p> <?php } ?> <form action="registration.php" method="post"> <table> <tr><td><label for="firstName"<?php validateField( "firstName", $missingFields ) ?>>First name *</label> </td><td><input type="text" name="firstName" id="firstName" value="<?php setValue( "firstName" ) ?>" /></td></tr> <tr><td><label for="lastName"<?php validateField( "lastName", $missingFields ) ?>>Last name *</label></td><td><input type="text" name="lastName" id="lastName" value="<?php setValue( "lastName" ) ?>" /></td></tr> <tr><td><label for="password1"<?php if ( $missingFields ) echo ' class="error"' ?>>Choose a password *</label></td><td><input type="password" name="password1" id="password1" value="" /></td></tr> <tr><td><label for="password2"<?php if ( $missingFields ) echo ' class="error"' ?>>Retype password *</label></td><td><input type="password" name="password2" id="password2" value="" /></td></tr> <tr><td><label<?php validateField( "gender", $missingFields ) ?>>Your gender: *</label></td><td><label for="genderMale">Male</label><input type="radio" name="gender" id="genderMale" value="M"<?php setChecked( "gender", "M" )?>/> <label for="genderFemale">Female</label><input type="radio" name="gender" id="genderFemale" value="F"<?php setChecked( "gender", "F" )?> /></td></tr> <tr><td><label for="favoriteWidget">What's your favorite widget? *</label></td><td><select name="favoriteWidget" id="favoriteWidget" size="1"> <option value="superWidget"<?php setSelected( "favoriteWidget", "superWidget" ) ?>>The SuperWidget</option> <option value="megaWidget"<?php setSelected( "favoriteWidget", "megaWidget" ) ?>>The MegaWidget</option> <option value="wonderWidget"<?php setSelected( "favoriteWidget", "wonderWidget" ) ?>>The WonderWidget</option> </select></td></tr> <tr><td><label for="newsletter" >Do you want to receive our newsletter?</label></td><td><input type="checkbox" name="newsletter" id="newsletter" value="yes"<?php setChecked( "newsletter", "yes" ) ?> /></td></tr> <tr><td><label for="comments">Any comments?</label></td><td><textarea name="comments" id="comments" rows="4" cols="50"><?php setValue( "comments" ) ?></textarea></td></tr> <tr><td><input type="submit" name="submitButton" id="submitButton" value="Send Details" /></td><td><input type="reset" name="resetButton" id="resetButton" value="Reset Form" style="margin-right: 20px;" /></td></tr> </form> <?php } function displayThanks() { ?> <h1>Thank You</h1> <p>Thank you, your application has been received.</p> <?php } ?> </body> </html>