11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 13• WORKING WITH HTML FORMSwww.it-ebooks.infoa bit of work has been put into automating the task of forms creation and user input validation. Onesuch solution is the HTML_QuickForm2 package, available through the PEAR repository.HTML_QuickForm2 is much more than a simple forms-generation class; it offers more than 20XHTML-compliant form elements, client- and server-side validation, the ability to integrate withtemplating engines such as Smarty (an extensible model that allows you to create your own customelements; see Chapter 19 for more about Smarty), and much more.■ Note HTML_QuickForm2 supersedes the HTML_QuickForm package introduced in prior editions of this book.HTML_QuickForm2 is a complete rewrite of its predecessor, updated to take advantage of <strong>PHP</strong> 5-specific features.Installing HTML_QuickForm2To take advantage of HTML_QuickForm2’s features, you need to install it from PEAR. Because itdepends on HTML_Common2, another PEAR package capable of displaying and manipulating HTMLcode, you need to install HTML_Common2 also, which is done automatically by passing the --onlyreqdeps flag to the install command. Note that at the time of this writing HTML_QuickForm2 isdeemed to be an alpha release, so you’ll need to append -alpha to the end of the package name.%>pear install --onlyreqdeps HTML_QuickForm2-alphadownloading HTML_QuickForm2-0.4.0.tgz ...Starting to download HTML_QuickForm2-0.4.0.tgz (101,758 bytes).......................done: 101,758 bytesdownloading HTML_Common2-2.0.0RC1.tgz ...Starting to download HTML_Common2-2.0.0RC1.tgz (7,598 bytes)...done: 7,598 bytesinstall ok: channel://pear.php.<strong>net</strong>/HTML_Common2-2.0.0RC1install ok: channel://pear.php.<strong>net</strong>/HTML_QuickForm2-0.4.0Creating and Validating a Simple FormCreating a form and validating form input is a breeze using HTML_QuickForm2. It can dramaticallyreduce the amount of code you need to write to perform even complex form validation, whilesimultaneously continuing to provide the designer with enough flexibility to stylize the form using CSS.For instance, Figure 13-2 depicts a form that requires the user to supply three pieces of data: name, e-mail address, and favorite programming language. We can use HTML_QuickForm2 to both render andvalidate the form and to provide convenient features such as automatically repopulating the form withthe data that passes validation tests (in this case, the developer name had been properly supplied).298

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!