Page 284 - Beginning PHP 5.3
P. 284

Part III: Using PHP in Practice
                Finally, try filling in all the required fields and clicking Send Details again. This time, you should see
                the thank-you message.






































                  Figure 9-7
                How It Works
                The script kicks off with the standard XHTML page header. It includes an additional CSS class for the
                red error boxes:

                        <style type=”text/css”>
                          .error { background: #d33; color: white; padding: 0.2em; }
                        </style>

                Next, the script checks to see if the form has been submitted. It does this by looking for the existence
                of the submitButton field. If present, it means that the Send Details button has been clicked and the
                form received, and the script calls a processForm() function to handle the form data. However, if
                the form hasn’t been displayed, it calls displayForm() to display the blank form, passing in an
                empty array (more on this in a moment):

                    if ( isset( $_POST[“submitButton”] ) ) {
                      processForm();
                    } else {
                      displayForm( array() );
                    }


              246





                                                                                                      9/21/09   7:23:42 PM
          c09.indd   246
          c09.indd   246                                                                              9/21/09   7:23:42 PM
   279   280   281   282   283   284   285   286   287   288   289