Page 275 - Beginning PHP 5.3
P. 275

Chapter 9: Handling HTML Forms with PHP

                       Try It Out     A Registration Form with Multi-Value Fields
                         Here are the registration form and form handler you created earlier, but this time the form includes a
                         multi-select list box for the “favorite widget” selection and two checkboxes to allow the user to sign
                         up for two different newsletters. The form handler deals with these multi-value fields, displaying their
                         values within the Web page.
                         Save the following form as registration_multi.html in your document root folder:

                             <!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>Membership Form</title>
                                 <link rel=”stylesheet” type=”text/css” href=”common.css” />
                               </head>
                               <body>
                                 <h1>Membership Form</h1>

                                 <p>Thanks for choosing to join The Widget Club. To register, please fill
                             in your details below and click Send Details.</p>
                                 <form action=”process_registration_multi.php” method=”post”>
                                   <div style=”width: 30em;”>
                                     <label for=”firstName”>First name</label>
                                     <input type=”text” name=”firstName” id=”firstName” value=”” />

                                     <label for=”lastName”>Last name</label>
                                     <input type=”text” name=”lastName” id=”lastName” value=”” />

                                     <label for=”password1”>Choose a password</label>
                                     <input type=”password” name=”password1” id=”password1” value=”” />
                                     <label for=”password2”>Retype password</label>
                                     <input type=”password” name=”password2” id=”password2” value=”” />

                                     <label for=”genderMale”>Are you male...</label>
                                     <input type=”radio” name=”gender” id=”genderMale” value=”M” />
                                     <label for=”genderFemale”>...or female?</label>
                                     <input type=”radio” name=”gender” id=”genderFemale” value=”F” />
                                     <label for=”favoriteWidgets”>What are your favorite widgets?</label>
                                     <select name=”favoriteWidgets[]” id=”favoriteWidgets” size=”3”
                             multiple=”multiple”>
                                       <option value=”superWidget”>The SuperWidget</option>
                                       <option value=”megaWidget”>The MegaWidget</option>
                                       <option value=”wonderWidget”>The WonderWidget</option>
                                     </select>
                                     <label for=”newsletterWidgetTimes”>Do you want to receive our
                             ‘Widget Times’ newsletter?</label>
                                     <input type=”checkbox” name=”newsletter[]” id=”newsletterWidget
                             Times” value=”widgetTimes” />



                                                                                                         237





                                                                                                      9/21/09   7:23:39 PM
          c09.indd   237
          c09.indd   237                                                                              9/21/09   7:23:39 PM
   270   271   272   273   274   275   276   277   278   279   280