Home > Backend Development > PHP Tutorial > Using HTML forms with PHP 1_PHP tutorial

Using HTML forms with PHP 1_PHP tutorial

WBOY
Release: 2016-07-13 17:25:44
Original
774 people have browsed it

The ability to easily operate on information submitted by users through HTML forms has always been one of PHP's strengths. In fact, PHP version 4.1 adds several new methods of accessing 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. 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 version 3.0 or higher. You need a basic understanding of PHP itself and creating HTML forms.
HTML Forms
As you read this article, you will see how different types of HTML form elements provide information that PHP can access. 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 values ​​to the URL, as shown below:
http://www.vanguardreport.com/ formaction.php?
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 values ​​as global variables:

Listing 2. As global variables Form value
echo "Ship = ".$ship;
echo "
";
echo "Tripdate = ".$tripdate;
echo "
";
echo "Exploration = ".$exploration;
echo "
";
echo "Contact = ".$contact;
?>

Generated Web The page displays the submitted values:

Ship = Midnight Runner
Tripdate = 12-15-2433
Exploration = yes
Contact =

(as you will see later As shown, Contact has no value because the box is not checked).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532018.htmlTechArticleThe ability to easily operate on information submitted by users through HTML forms has always been one of the advantages of PHP. In fact, PHP version 4.1 adds several new ways to access this information and works...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template