Page 493 - Beginning PHP 5.3
P. 493

Chapter 15: Making Your Job Easier with PEAR
                           Web Forms the Easy Way with

                       HTML_QuickForm

                           Just as  HTML_Table  lets you create HTML tables programmatically  —  thereby making your code clean
                         and flexible  —  the   HTML_QuickForm  package provides a class for creating Web forms without needing
                          to include a single line of HTML in your scripts. What ’ s more,   HTML_QuickForm  can process the forms it
                          creates, relieving you of the burden of writing (and testing) your own validation, filtering, and error -
                           reporting code.

                            In the following sections you take a brief look at the functionality available in the   HTML_QuickForm
                         package, and then you create a membership form script using the power of   HTML_QuickForm .

                           Installing HTML_QuickForm

                           Installation of  HTML_QuickForm  is much as you ’ d expect. On Ubuntu, for example, just run  pear
                         install  - - alldeps HTML_QuickForm :

                             $ pear install --alldeps HTML_QuickForm
                             downloading HTML_QuickForm-3.2.10.tgz ...
                             Starting to download HTML_QuickForm-3.2.10.tgz (101,851 bytes)
                             .......................done: 101,851 bytes
                             downloading HTML_Common-1.2.4.tgz ...
                             Starting to download HTML_Common-1.2.4.tgz (4,519 bytes)
                             ...done: 4,519 bytes
                             install ok: channel://pear.php.net/HTML_Common-1.2.4
                             install ok: channel://pear.php.net/HTML_QuickForm-3.2.10

                             $
                           Once installed, you should find that there are some example scripts in the  doc/HTML_QuickForm/docs/
                         folder inside your PEAR folder. You can also read the full documentation for   HTML_QuickForm  at
                           http://pear.php.net/manual/en/package.html.html-quickform.php .


                           Working with HTML_QuickForm
                           To use  HTML_QuickForm , you first create a new  HTML_QuickForm  object, and then call various methods to
                         add elements  —  such as fields and labels  —  to the form. You can also add validation rules to make sure
                         that the data entered for each field is correct, and filters to remove unacceptable data from each field. You
                         can then call various methods to validate the form, process the form, or display the form in the page
                         (including any error messages to display to the user).














                                                                                                         455





                                                                                                      9/21/09   9:14:51 AM
          c15.indd   455
          c15.indd   455                                                                              9/21/09   9:14:51 AM
   488   489   490   491   492   493   494   495   496   497   498