Page 277 - Beginning PHP 5.3
P. 277
Chapter 9: Handling HTML Forms with PHP
$favoriteWidgets = preg_replace( “/, $/”, “”, $favoriteWidgets );
$newsletters = preg_replace( “/, $/”, “”, $newsletters );
?>
<dl>
<dt>First name</dt><dd><?php echo $_POST[“firstName”]?></dd>
<dt>Last name</dt><dd><?php echo $_POST[“lastName”]?></dd>
<dt>Password</dt><dd><?php echo $_POST[“password1”]?></dd>
<dt>Retyped password</dt><dd><?php echo $_POST[“password2”]?></dd>
<dt>Gender</dt><dd><?php echo $_POST[“gender”]?></dd>
<dt>Favorite widgets</dt><dd><?php echo $favoriteWidgets?></dd>
<dt>You want to receive the following newsletters:</dt><dd>
<?php echo $newsletters?></dd>
<dt>Comments</dt><dd><?php echo $_POST[“comments”]?></dd>
</dl>
</body>
</html>
As before, fill out the form, and try selecting a couple of the “favorite widget” options and both
“newsletter” checkboxes. Now submit the form. Notice how the PHP script handles the multi-value
fields. You can see a sample form in Figure 9-5 and the resulting script output in Figure 9-6.
Figure 9-5
239
9/21/09 7:23:39 PM
c09.indd 239
c09.indd 239 9/21/09 7:23:39 PM