PHP Class for Generating HTML Forms

The PHP Form Class is a light weight yet very flexible class for generating (x)html forms. It contains methods for generating common form elements such as inputs of all types, text areas, select lists, and more. Not only can it be used to create the common input types such as text boxes, radio buttons, check boxes, and submit buttons, it can also be used to create the new HTML5 input types. The method provided for adding attributes is also very flexible, allowing you to add any attribute, including custom attributes, to any element using associative array syntax.

Generic functions are included that allow you to add an element of any type, perhaps for containing your form elements. A property setting allows you to specify XHTML syntax, for closing empty tags and expanding minimized or boolean attributes.

All this functionality, yet the class file is very brief and the syntax for using it very concise. View the PHP Form Class file as well as an example and source code demonstrating its use. The PHP Form Class file and an example are provided in the download file. Documentation is also provided.

More Information

See the PHP Table Class which is well suited for use with the form class. See also the PHP Order Form for a demonstration of the form class used in combination with the PHP Table Class.