Tuesday, August 3, 2010

PHP PEAR's HTML_QuickForm

SkyHi @ Tuesday, August 03, 2010
Introduction

Programmers are often told not to reinvent the wheel, and that the best programmers borrow from others before they start to build something themselves. PHP, being primarily a web language, sees a lot of reinventing in regards to form display, processing and validation. However, there's a great PEAR package that needs a little more exposure: HTML_QuickForm. It makes handling the rendering and display of forms, and more usefully, both client and server-side validation, quick and easy. This article will take you through the basics of that package. It assumes familiarity with HTML form elements, and reasonably basic PHP skills.


Installing HTML_QuickForm


The package has only two requirements: a version of PHP that is at least 4.2, and the HTML_Common package. At the time of writing, HTML_QuickForm 3.2.7 is the newest version of the package, and it requires HTML_Common 1.2.1. There are moves underfoot to rewrite both of these packages for PHP 5 (in the form of HTML_QuickForm2, and HTML_Common2), but as yet neither has been released.


You can check what PEAR packages are already installed by using pear list:



pear list
Installed packages:
===================
Package Version State
Archive_Tar 1.1 stable
Console_Getopt 1.2 stable
DB 1.6.2 stable
Date 1.4.6 stable
HTTP 1.2.2 stable
Image_Canvas 0.3.0 alpha
Image_Color 1.0.2 stable
Image_Graph 0.7.2 alpha
Mail 1.1.3 stable
Net_SMTP 1.2.6 stable
Net_Socket 1.0.1 stable
PEAR 1.3.2 stable
Validate 0.6.3 beta
XML_Parser 1.0.1 stable
XML_RPC 1.1.0 stable




This machine doesn't have either HTML_QuickForm or HTML_Common, so they'll need to be installed.


#pear install HTML_Common
downloading HTML_Common-1.2.3.tgz ...
Starting to download HTML_Common-1.2.3.tgz (4,746 bytes)
.....done: 4,746 bytes
install ok: HTML_Common 1.2.3

#pear install HTML_QuickForm
downloading HTML_QuickForm-3.2.7.tgz ...
Starting to download HTML_QuickForm-3.2.7.tgz (102,475 bytes)
........................done: 102,475 bytes
install ok: HTML_QuickForm 3.2.7




REFERENCES
http://www.phpbuilder.com/columns/ian_gilfillan20061024.php3
http://www.devarticles.com/c/a/Web-Design-Usability/Using-HTML-QuickForm-To-Manage-Web-Forms-Part-1/1/
http://learnwithharv.com/blog/quick-forms-using-phps-pearquick_form/
http://pear.php.net/package/HTML_QuickForm/download
http://pear.php.net/package/HTML_Common2/download