Using HTML form _php with PHP

Source: Internet
Author: User
The ability to easily manipulate the information that users submit via HTML forms has been one of the advantages of PHP. In fact, PHP version 4.1 adds several new ways to access this information and effectively removes one of the most commonly used methods from previous releases. This article explores different ways to use the information submitted on an HTML form and uses both earlier versions of PHP and newer versions. This article begins with a study of a single value, and then constructs a page that provides general access to any available form values.

Note: This article assumes that you have access to a WEB server running PHP version 3.0 or later. You need to have a basic understanding of PHP itself and the creation of HTML forms.

HTML form



As you read through this article, you'll see how different types of HTML form elements provide information that PHP can access. For this example, I used a simple information form that consists of two text fields, two check boxes, and a selection box that allows multiple items:


 

Listing 1. HTML form



<title>Tour information</title>



Mission Information












Without specifying a method, the form uses the default method GET, which the browser uses to append the form value to the URL, as follows:

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



Old-fashioned: accessing global variables



The code shown in Listing 2 handles the form values as global variables:


 

Listing 2. Form values as global variables


echo "ship =". $ship;

echo "
";

echo "tripdate =". $tripdate;

echo "
";

echo "exploration =". $exploration;

echo "
";

echo "contact =". $contact;

?>




The generated Web page displays the submitted values:


 

ship = Midnight Runner

Tripdate = 12-15-2433

Exploration = yes

Contact =




(as you'll see later, the contact has no value, because that box is not selected).
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.