Current version: 1.0b2 (16-Aug-2005)
Second Beta release is out. It includes more fields, some bug fixes and the beginning of database support.
About
FormBuilder is a PHP class that simplifies the process of creation and validation of HTML forms. It can also output the results in a text form and email them.
FormBuilder in essence manages a collection of field classes that implement a standard interface defined by the FormField class. Classes currently implemented include text fields, radio buttons, checkboxes, popup menus, date/time, etc.
The generated form can be fully customized through CSS.
The current version of FormBuilder is already very usable, but there are some improvements in planning: Better validation, more types of Fields and database integration.
Example
The best way to explain how FormBuilder works is to go through a simple example - a guest book:
1: // The first step is to include the FormBuilder class
2:
3: require_once('FormBuilder.php');
4:
5: // Then FormBuilder needs to be initialized
6:
7: $form = new FormBuilder();
8:
9: // insert some fields into the form
10:
11: $form->addField(new TextField('Name:', 'name', 25, 2, 30));
12: $form->addField(new TextAreaField('Text:', 'textArea', 1, 100, 5, 40));
13: $form->addField(new SubmitField('submit', 'Send'));
14:
15: // Next, check if the form has already been submitted,
16: // or if this is the first time the form is displayed
17:
18: if ($form->isSubmitted('submit'))
19: {
20: // Form has been submitted, so validate it.
21: $form->validate();
22:
23: if ($form->isValid())
24: {
25: // The form is valid, display some success message
26: echo 'Thank you for submitting the form!';
27:
28: // now the contents of the form can be sent by email,
29: // displayed on screen, or stored in a database.
30: }
31: else
32: {
33: // Form is invalid, show an error message and display the
34: // form again
35:
36: echo 'The form is invalid, please correct the highlighted '.
37: 'fields, and submit again';
38:
39: $form->display();
40: }
41: }
42: else
43: {
44: // This is the first time the page is loaded, so display the form
45: $form->display();
46: }