The ability to easily operate on information submitted by users through HTML forms has always been one of the advantages of php (as the current mainstream development language) . In fact, PHP version 4.1 adds several new ways to access this information and effectively removes one of the most commonly used methods in previous versions. This article examines different ways of working with information submitted on an HTML form, using both older and newer versions of php(a popular development language today). This article starts by studying a single value and then builds a page that can generally access any available form value. Note: This article assumes you have access to a web server running php
(as the current mainstream development language)
version 3.0 or higher. You need to have a basic understanding of php(as the current mainstream development language) itself and creating HTML forms.
HTML Form
In the process of reading this article, you will see how different types of HTML form elements are provided by php(as the current mainstream development language)
Information that can be accessed. For this example, I used a simple information form consisting of two text fields, two checkboxes, and a select box that allows multiple items: Listing 1. HTML form
Tour Information Mission Information
With no method specified, the form uses the default method GET, which is used by the browser to append the form value to the URL, as shown below:
http://www.vanguardreport.com/formaction.php
(as the current mainstream development language)
?
ship=Midnight+Runner&tripdate=12-15-2433&exploration=yes&crew =snertal&crew=gosny
Figure 1 shows the form itself.
Figure 1. HTML form
The old way: accessing global variables
The code shown in Listing 2 handles the form value as a global variable:
Listing 2. Form values as global variables
🎜> echo "
";
echo "Tripdate = ".$tripdate; echo "
"; echo "Exploration = ".$exploration;
echo "
";
echo "Contact = ".$contact;
?>
The generated Web page displays the submitted value:
> Ship = Midnight Runner
Tripdate = 12-15-2433
Exploration = yes
Contact =
(As you will see later, Contact has no value because it is not selected That box).
The notation in Listing 2 is certainly convenient, but it only works when the php
(as the current mainstream development language)
directive register_globals is set to on. Available. Before version 4.2, this was the default setting, and many php
(as the current mainstream development language)
developers were not even aware of this problem. However, starting from version 4.2, register_globals. The default setting is off, in which case the notation does not work properly because the variable
is no longer created and initialized with the appropriate value.
http://www.bkjia.com/PHPjc/508873.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/508873.htmlTechArticleThe ability to more easily operate on information submitted by users through HTML forms has always been php (as the current One of the advantages of mainstream development languages). In fact, php (as the current mainstream...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn