![]() Back to www.deitel.com |
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.14: form.php --> |
5 <!-- Read information sent from form.html --> |
6 |
7 <html xmlns = "http://www.w3.org/1999/xhtml"> |
8 <head> |
9 <title>Form Validation</title> |
10 </head> |
11 |
12 <body style = "font-family: arial,sans-serif"> |
13 |
14 <?php |
15 extract( $_POST ); |
16 |
17 // determine whether phone number is valid and print |
18 // an error message if not |
19 if ( !ereg( "^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$", |
20 $phone ) ){ |
21 |
22 print( "<p><span style = \"color: red; |
23 font-size: 2em\"> |
24 INVALID PHONE NUMBER</span><br /> |
25 A valid phone number must be in the form |
26 <strong>(555)555-5555</strong><br /> |
27 <span style = \"color: blue\"> |
28 Click the Back button, enter a valid phone |
29 number and resubmit.<br /><br /> |
30 Thank You.</span></p></body></html>" ); |
31 |
32 die(); // terminate script execution |
33 } |
34 ?> |
35 |
36 <p>Hi |
37 <span style = "color: blue"> |
38 <strong> |
39 <?php print( "$fname" ); ?> |
40 </strong> |
41 </span>. |
42 Thank you for completing the survey.<br /> |
43 |
44 You have been added to the |
45 <span style = "color: blue"> |
46 <strong> |
47 <?php print( "$book " ); ?> |
48 </strong> |
49 </span> |
50 mailing list. |
51 </p> |
52 <strong>The following information has been saved |
53 in our database:</strong><br /> |
54 |
55 <table border = "0" cellpadding = "0" cellspacing = "10"> |
56 <tr> |
57 <td bgcolor = "#ffffaa">Name </td> |
58 <td bgcolor = "#ffffbb">Email</td> |
59 <td bgcolor = "#ffffcc">Phone</td> |
60 <td bgcolor = "#ffffdd">OS</td> |
61 </tr> |
62 |
63 <tr> |
64 <?php |
65 |
66 // print each form field's value |
67 print( "<td>$fname $lname</td> |
68 <td>$email</td> |
69 <td>$phone</td> |
70 <td>$os</td>" ); |
71 ?> |
72 </tr> |
73 </table> |
74 |
75 <br /><br /><br /> |
76 <div style = "font-size: 10pt; text-align: center"> |
77 This is only a sample form. |
78 You have not been added to a mailing list. |
79 </div> |
80 </body> |
81 </html> |