Page 501 - Beginning PHP 5.3
P. 501

Chapter 15: Making Your Job Easier with PEAR
                         Next, open the common.inc.php file inside the book_club_2 folder and modify the CSS in the
                         displayPageHeader() function at the top of the file. This is necessary to make the CSS compatible
                         with the markup produced by HTML_QuickForm. Replace the old displayPageHeader() function with
                         the following:

                             function displayPageHeader( $pageTitle, $membersArea = false ) {
                             ?>
                             <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
                               “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
                             <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
                               <head>
                                 <title><?php echo $pageTitle?></title>
                                 <link rel=”stylesheet” type=”text/css” href=”<?php if ( $membersArea )
                             echo “../” ?>../common.css” />
                                 <style type=”text/css”>
                                   th { text-align: left; background-color: #bbb; }
                                   th, td { padding: 0.4em; }
                                   tr.alt td { background: #ddd; }
                                   .error { background: #d33; color: white; padding: 0.2em; margin:
                             0.2em 0 0.2em 0; font-size: 0.9em; }
                                   fieldset { border: none; }
                                   ol {list-style-type: none; }
                                   input, select, textarea { float: none; margin: 1em 0 0 0; width:
                             auto; }
                                   div.element { float: right; width: 57%; }
                                   div.element label { display: inline; float: none; }
                                 </style>
                               </head>
                               <body>

                                 <h1><?php echo $pageTitle?></h1>
                             <?php
                             }
                         Now, rewrite the register.php script in the book_club_2 folder to use HTML_QuickForm. Replace the
                          old code in the script with the following new code:
                             <?php

                             require_once( “common.inc.php” );
                             require_once( “HTML/QuickForm.php” );
                             require_once( “HTML/QuickForm/Renderer/Tableless.php” );

                             $form = new HTML_QuickForm( “”, “post”, “register.php”, “”,
                             array( “style” => “width: 30em;” ), true );
                             $form->removeAttribute( “name” );
                             addElements( $form );
                             addRules( $form );
                             $form->setRequiredNote( “” );

                             if ( $form->isSubmitted() and $form->validate() ) {
                               $form->process( “processForm” );




                                                                                                         463





                                                                                                      9/21/09   9:14:55 AM
          c15.indd   463
          c15.indd   463                                                                              9/21/09   9:14:55 AM
   496   497   498   499   500   501   502   503   504   505   506