Page 500 - Beginning PHP 5.3
P. 500
Part III: Using PHP in Practice
For example, you could add a rule to check that the submitted username field is no longer than ten
characters:
$form- > addRule( “username”, “Username must be no longer than 10 characters”,
‘maxlength’, 10 );
Try It Out A Registration Form using HTML_QuickForm
To show just how powerful and useful HTML_QuickForm is, in this example you rewrite the
register.php book club registration script from Chapter 14, using HTML_QuickForm to handle
the form display and validation.
Before you start, though, install an additional PEAR package called HTML_QuickForm_Renderer_
Tableless. By default, HTML_QuickForm outputs each form using an HTML table to hold the form
fields and labels. HTML forms created without using tables are more flexible and can be easier to
restyle. What’s more, the tables-based forms produced by HTML_QuickForm aren’t valid XHTML.
HTML_QuickForm_Renderer_Tableless is a renderer class that replaces the default HTML_
QuickForm renderer and generates XHTML-compliant, tables-free form markup.
At the time of writing, HTML_QuickForm_Renderer_Tableless is a beta package, which means it
can’t be installed using a default PEAR setup:
$ pear install --alldeps HTML_QuickForm_Renderer_Tableless
Failed to download pear/HTML_QuickForm_Renderer_Tableless within preferred
state “stable”, latest release is version 0.6.1, stability “beta”, use
“channel://pear.php.net/HTML_QuickForm_Renderer_Tableless-0.6.1” to install
Cannot initialize ‘channel://pear.php.net/HTML_QuickForm_Renderer_Tableless’,
invalid or missing package file
Package “channel://pear.php.net/HTML_QuickForm_Renderer_Tableless” is not
valid
install failed
$
By the time you read this you may find that the package is no longer in beta, in which case you can
install it in the normal way — that is, using pear install --alldeps HTML_QuickForm_Renderer_
Tableless. If the package is still in beta, you can install it by specifying the channel explicitly, as
follows:
$ pear install --alldeps channel://pear.php.net/HTML_QuickForm_Renderer_
Tableless-0.6.1
downloading HTML_QuickForm_Renderer_Tableless-0.6.1.tgz ...
Starting to download HTML_QuickForm_Renderer_Tableless-0.6.1.tgz (6,828
bytes)
.....done: 6,828 bytes
install ok: channel://pear.php.net/HTML_QuickForm_Renderer_Tableless-0.6.1
$
Now you’re ready to modify the book club application code. First, copy the book_club folder (and its
files) that you created in Chapter 14 to a new folder, book_club_2, in your document root. This will
preserve your original application files.
462
9/21/09 9:14:55 AM
c15.indd 462 9/21/09 9:14:55 AM
c15.indd 462