Developing HTML Forms in PHP using QuickForm
The power of PHP rests on its simplicity and speed. One of the common uses of dynamic pages is the processing of HTML forms. PHP does not offer any functions for the development of web forms so managing one in PHP tends to be nothing more than a sequence of print statements. The PEAR library contains the HTML_QUICKFORM package that provides all the necessary classes and methods to display and manage HTML forms.
QuickForm Package
The HTML_QUICKFORM package (I will be referring to it as QuickForm) provides a set of classes creating, validating, processing HTML forms. Instead of printing form elements one-by-one, we can use its methods to define a form structure that handles the form. QuickForm automatically preserves default values for our elements across form submission, displays error messages, allows custom server-side validation and filtering that can be applied to individual fields and/or the complete form and generates JavaScript code for client-side validation. Furthermore, it simplifies file uploads.
The only reason why someone may feel reluctant in using QuickForm is due to the lack of proper documentation. However, this should not hold you back as this series of articles intends to cover the majority of the package. Among others, we will be concentrating on:
- Displaying a form
- Processing the from input
- Field validation
- File Uploading
- Using SMARTY for rendering the form
The goal of the articles is to demonstrate how we can make use of QuickForm and SMARTY to develop a web application.
Requisites
QuickForm not part of the standard PEAR installation. Therefore, we need to download it and place it in the HTML directory of PEAR. Please note that the HTML_COMMON package needs to be present as well.
If the following line does not return an error then you have QuickForm present on your system.
require('HTML/QuickForm.php');
In the case that you are working on a shared host environment and you do not have access to the PEAR directory and therefore you cannot install HTML_QUICKFORM then you can always download PEAR, HTML_COMMON and HTML_QUICKFORM to your webspace. Instructions on the manual installation of PEAR can be found on the PEAR web site.







