Page 294 - Beginning PHP 5.3
P. 294

Part III: Using PHP in Practice
                signup process; the fields for the current step are displayed as normal, and the fields for the other two
                steps are displayed as hidden fields. For example,   displayStep2()  outputs hidden fields to store the
                values for   firstName ,  lastName ,  newsletter , and  comments , while displaying the fields for the
                current step (  gender  and  favoriteWidget ):

                            <input type=”hidden” name=”step” value=”2” />
                            <input type=”hidden” name=”firstName” value=”<?php setValue
                    ( “firstName” ) ?>” />
                            <input type=”hidden” name=”lastName” value=”<?php setValue(
                    “lastName” ) ?>” />
                            <input type=”hidden” name=”newsletter” value=”<?php setValue
                    ( “newsletter” ) ?>” />
                            <input type=”hidden” name=”comments” value=”<?php setValue
                    ( “comments” ) ?>” />
                            <label>Your gender:</label>
                            <label for=”genderMale”>Male</label>
                            <input type=”radio” name=”gender” id=”genderMale” value=”M”<?php
                    setChecked( “gender”, “M” )?>/>
                            <label for=”genderFemale”>Female</label>
                            <input type=”radio” name=”gender” id=”genderFemale” value=”F”<?php
                    setChecked( “gender”, “F” )?> />
                            <label for=”favoriteWidget”>What’s your favorite widget? *</label>
                            <select name=”favoriteWidget” id=”favoriteWidget” size=”1”>
                              <option value=”superWidget”<?php setSelected( “favoriteWidget”,
                    “superWidget” ) ?>>The SuperWidget</option>
                              <option value=”megaWidget”<?php setSelected( “favoriteWidget”,
                    “megaWidget” ) ?>>The MegaWidget</option>
                              <option value=”wonderWidget”<?php setSelected( “favoriteWidget”,
                    “wonderWidget” ) ?>>The WonderWidget</option>
                            </select>

                      By including (and populating) all the fields  —  whether visible or hidden  —  in each of the three steps,
                the script ensures that the entire signup data is sent back to the server each time a form is submitted,
                thereby allowing the data to be carried across the three steps.
                  Steps 2 and 3 also include Back and Next buttons, whereas step 1 just includes a Next button. Finally,
                  displayThanks()  simply displays the thank - you message to the user.





















              256





                                                                                                      9/21/09   7:23:47 PM
          c09.indd   256
          c09.indd   256                                                                              9/21/09   7:23:47 PM
   289   290   291   292   293   294   295   296   297   298   299