Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
Internet & World Wide Web How to Program, 3/e
Internet & World Wide Web How to Program, 3/e

ISBN:
0-13-145091-3
© 2004
pages: 1420

Order
Amazon logo

This tutorial shows how to use a PHP program to receive and process data input by a user in an XHTML form. The sample program also uses the regular-expression capabilities that we presented in the preceding tutorial

[Note: This tutorial is an excerpt (Section 26.5) of Chapter 26, PHP, from our textbook Internet & World Wide Web How to Program, 3/e. This tutorial may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., INTERNET & WORLD WIDE WEB HOW TO PROGRAM, 3/E, 2004, pp.899–900;916-922. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
26.5 Form Processing and Business Logicc
XHTML forms enable Web pages to collect data from users and send it to a Web server for processing. Interaction of this kind between users and Web servers is vital to e-commerce applications. Such capabilities allow users to purchase products, request information, send and receive Web-based e-mail, perform online paging and take advantage of various other online services. Figure 26.13 uses an XHTML form to collect information about users for the purpose of adding them to a mailing list. The type of registration form in this example could be used by a software company to acquire profile information before allowing users to download software.
Fig. 26.13 XHTML form for gathering user input. (Part 1 of 4.)
1   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3   
4   <!-- Fig. 26.13: form.html -->
5   <!-- Form for use with the form.php program -->
6   
7   <html xmlns = "http://www.w3.org/1999/xhtml">
8       <head>
9         <title>Sample form to take user input in XHTML</title>
10      </head>
11
12      <body>
13   
14         <h1>This is a sample registration form.</h1>
15         Please fill in all fields and click Register.
16   
17         <!-- post form data to form.php -->
18         <form method = "post" action = "form.php">
19            <img src = "images/user.gif" alt = "User" /><br />
20            <span style = "color: blue">
21               Please fill out the fields below.<br />
22            </span>
23
24            <!-- create four text boxes for user input -->
25            <img src = "images/fname.gif" alt = "First Name" />
26            <input type = "text" name = "fname" /><br />
27   
28            <img src = "images/lname.gif" alt = "Last Name" />
29            <input type = "text" name = "lname" /><br />
30   
31            <img src = "images/email.gif" alt = "Email" />
32            <input type = "text" name = "email" /><br />
33   
34            <img src = "images/phone.gif" alt = "Phone" />
35            <input type = "text" name = "phone" /><br />
36   
37            <span style = "font-size: 10pt">
38               Must be in the form (555)555-5555</span>
39             <br /><br />
40   
41            <img src = "images/downloads.gif"
42               alt = "Publications" /><br />
43
44            <span style = "color: blue">
45               Which book would you like information about?
46            </span><br />
47
48            <!-- create drop-down list containing book names -->
49            <select name = "book">
50               <option>Internet and WWW How to Program 3e</option>
51               <option>C++ How to Program 4e</option>
52               <option>Java How to Program 5e</option>
53               <option>XML How to Program 1e</option>
54            </select>
55            <br /><br />
56
57            <img src = "images/os.gif" alt = "Operating System" />
58            <br /><span style = "color: blue">
59               Which operating system are you currently using?
60            <br /></span>
61
62            <!-- create five radio buttons -->
63            <input type = "radio" name = "os" value = "Windows XP"
64               checked = "checked" />
65               Windows XP
66
67            <input type = "radio" name = "os" value =
68               "Windows 2000" />
69               Windows 2000
70
71            <input type = "radio" name = "os" value =
72               "Windows 98" />
73               Windows 98<br />
74
75            <input type = "radio" name = "os" value = "Linux" />
76               Linux
77
78            <input type = "radio" name = "os" value = "Other" />
79               Other<br />
80   
81            <!-- create a submit button -->
82            <input type = "submit" value = "Register" />
83          </form>
84      
85    </body>
86   </html>
 
Page 1 | 2 | 3
 
Other PHP Tutorials
PHP Tutorial 1: Introduction to PHP
PHP Tutorial 2: Creating Simple PHP Programs
PHP Tutorial 3: String Processing and Regular Expressions
PHP Tutorial 4: Form Processing and Business Logic (You are here)