Page 293 - Beginning PHP 5.3
P. 293

Chapter 9: Handling HTML Forms with PHP
                         step field wasn’t submitted (or its value was invalid), the script assumes the user has just started
                         the signup process and displays the form for the first step:

                             if ( isset( $_POST[“step”] ) and $_POST[“step”] >= 1 and $_POST[“step”] <= 3 ) {
                               call_user_func( “processStep” . (int)$_POST[“step”] );
                             } else {
                               displayStep1();
                             }

                         The next three functions — setValue(), setChecked(), and setSelected() — are identical to their
                         counterparts in registration.php.
                         Next come the three functions to process the forms submitted from each of the three steps.
                         processStep1() simply displays step 2:
                             function processStep1() {
                               displayStep2();
                             }
                            processStep2()  checks to see if the user clicked the Back button. If he did, step 1 is redisplayed;
                         otherwise it ’ s assumed the user clicked the Next button, so step 3 is displayed:

                             function processStep2() {
                               if ( isset( $_POST[“submitButton”] ) and $_POST[“submitButton”] ==
                             “ <  Back” ) {
                                 displayStep1();
                               } else {
                                 displayStep3();
                               }
                             }

                           In a similar fashion,  processStep3()  displays step 2 if the Back button was clicked, or the thank - you
                         page if Next was clicked:

                             function processStep3() {
                               if ( isset( $_POST[“submitButton”] ) and $_POST[“submitButton”] ==
                             “ <  Back” ) {
                                 displayStep2();
                               } else {
                                 displayThanks();
                               }
                             }

                           The remaining four functions  —  displayStep1() ,  displayStep2() ,  displayStep3() , and


                           displayThanks()  —  display forms for each of the three steps in the signup process, as well as the
                         final thank - you page. Notice that each of the step functions includes all of the form fields for the entire










                                                                                                         255





                                                                                                      9/21/09   7:23:46 PM
          c09.indd   255
          c09.indd   255                                                                              9/21/09   7:23:46 PM
   288   289   290   291   292   293   294   295   296   297   298