Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PHP TUTORIALS > USING HTML FORMS WITH PHP


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Using HTML forms with PHP
By Nicholas Chase - 2003-12-12 Page:  1 2 3 4 5 6

Access Single And Multiple Form Values

One of the advantages of PHP has always been the ability to easily manipulate information submitted by the user through an HTML form. In fact, PHP version 4.1 adds several new ways to access this information and effectively removes the one most commonly used in previous versions. This article looks at different ways to use the information submitted on an HTML form, in both older and more recent versions of PHP. It starts out by looking at individual values and builds to a page that can generically access any available form values.

Note: This article assumes that you have access to a Web server running PHP version 3.0 or above. You'll need a basic understanding of PHP itself, and of creating an HTML form.

The HTML form

During the course of the article, you'll look at how different types of HTML form elements provide information that PHP can access. For this example, I use a simple information form that consists of two text fields, two checkboxes, and a select box that permits multiple entries:

Listing 1. The HTML form


<html>
<head><title>Tour Information</title></head>

<body>

<h2>Mission Information</h2>

<form action="formaction.php">
  <table width="100%">
    <tr><td>Ship Name:</td><td><input type="text" name="ship" /></td></tr>

    <tr><td>Trip Date:</td><td><input type="text" name="tripdate" /></td></tr>
    <tr><td colspan="2">Mission Goals:</td></tr>

    <tr>
      <td><input type="checkbox" name="exploration" value="yes" />
               Exploration</td>
      <td><input type="checkbox" name="contact" value="yes" />
               Contact</td>

    </tr>
    <tr>
      <td valign="top">Crew species:  </td>
      <td>
        <select name="crew" multiple="multiple">

           <option value="xebrax">Xebrax</option>
           <option value="snertal">Snertal</option>
           <option value="gosny">Gosny</option>
        </select>

      </td>
    </tr>
    <tr><td colspan="2" align="center"><input type="submit" /></td></tr>
  </table>
</form>


</body>
</html>

Without a method specified, this form uses the default, GET, in which the browser appends form values to the URL, as in:


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. The HTML form
The HTML form



View Using HTML forms with PHP Discussion

Page:  1 2 3 4 5 6 Next Page: The Old Way: Accessing Global Variables

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.