Getting Work Done Through People
Getting People Done Through Work
form_gen.class.php Form generator
Documentation (42pg/996k)
Reference Tables (9pg/292k)
Form Generator, as its name implies, is a PHP utility used to generate html forms within a web page. Forms generated by Form Generator contain very detailed fields and fieldsets with complete name, id, and class markup for wide-ranging layout customization.
Form Generator does not do layout. It generates the form, fields and fieldsets only. The only layout specified by Form Generator is the order of the fields, which is dictated by the application using Form Generator.
form_gen.class features...
There are 25 different types of input fields:
There are 30 different parameters that may be applied to fields:
A fieldset is a container that contains fields. A field itself is a fieldset that may contain a legend (or header), label, the input field, any items to include before or after the field, a hint (or tool-tip) value, and an error value.
Fieldsets can contain fieldsets that can contain fields. There’s no limit to the depth of a fieldset although the deeper the more complicated it is to style.
The layout of a form is defined by styling the fieldsets and fields within the form. Each element of a field can be referenced by the style sheet and all available styles can be attributed to any element in a field.
Form Generator consists of the primary class, form_gen.class.php, an included file used to generate client-side JavaScript code, form_gen,class,js.php and the JavaScript foundation libraries provided by wForms (see wForms later in this document). An optional custom program, form_gen.post.php, is used for Ajax calls to capture and/or validate forms as the field data is entered or just prior to a form submit.
First, include the class library in your php document:
require_once('form_gen.class.php');
Next create an instance of the form_generator class:
$myform = new form_generator(array(
'foundations'=>'hint,repeat,switch,paging,validation,onblur,sync')
);
Or
$myform = new form_generator();
$myform->preProcess($fields);
* These two steps should be executed within the “<head>” portion of the document.
To start creating a form, call the “startForm” method:
$myform->startForm(array(
'form' => "MyFormName",
'id' => "MyFormID",
'action' => $PHP_SELF,
'method' => "post",
'enctype' => "multipart/form-data",
)
);
Next, create fieldsets and fields:
$myform->startFieldset('MyFieldSet','MyFieldSet Legend');
$myform->addField($fname,$foptions);
$myform->addField($fname,$foptions);
$myform->addField($fname,$foptions);
...
$myform->endFieldset();
Lastly, end the form:
$myform->endForm();
A form should always start with at least one fieldset and this will become the parent fieldset for all of the fields.
A typical method for generating fields is to define the fields in an array and call addField() in a foreach() loop.
$fields = array();
$fields['First_Field'] = array(
'Type' => "Text",
'Text' => "First Field",
'Size' => array(20,30),
'Default' => "default text",
'Hint' => "This field is required",
'Required' => true
);
$fields['Second_Field'] = array(
...
$fields['Third_Field'] = array(
...
foreach($fields as $fname => $fopt) {
$myform->addField($fname,$fopt);
}
“wForms is an open-source, unobtrusive JavaScript library that adds commonly needed behaviors to traditional web forms”
http://www.formassembly.com/wForms/
As stated above, wForms is a JavaScript library (actually a number of libraries or foundations) used to enhance the functionality of a typical web form.
wForms adds the capability to…
Form Generator incorporates and enhances many of the wForms functions, delivers the needed JavaScript when the class is instantiated, and tags all fields and fieldsets with the needed code to fully support wForms.
As a JavaScript library, wForms runs on the client browser based on the assignments given by Form Generator and on actions taken by the person using the form.
wForms works through the extensive use of style class names. Not just for applying styles to the form but more so for detecting form elements for actions such as validation. Form generator will automatically insert the correct class names and parameters for wForms based on the field and fieldset options.