14.6. Forms

Forms are the primary mechanism for accepting information from users. A form can use decorators, elements, validators, filters, and sub-forms. Place form classes in the module folder, in the forms folder. Place decorator classes in the forms/decorators folder. Place element classes in the forms/elements folder.

Here is the skeleton of a form for the Foo module:

<?php
/**
 * Form description
 *
 * @copyright   copyright info
 * @license     license info
 * @version     version info
 */
class Foo_Form_Example extends P4Cms_Form
{
    /**
     * Defines the elements that make up the example form.
     */
    public function init()
    {
        // set the method for the form to POST
        $this->setMethod('post');

        $this->addElement(
            'text',             // the element type
            'identifier',
            array(
                'label'         => 'Example',
                'required'      => true,
                'description'   => 'Enter some text for this example.',
            )
        );
    }
}

For details, see the Zend Form documentation.

14.6.1. Decorators

The forms in Perforce Chronicle use the decorator pattern to render elements and forms by means of the strategy pattern, which allows decorators to create, modify, and wrap markup, using a chaining mechanism to apply decorators in a specified order. For details, see the Zend Form Decorators documentation.

14.6.2. Elements

Elements implement the fields in forms that correspond to HTML form fields. To handle specialized input scenarios that cannot be handled using simple HTML form fields, you can create custom elements. For details, see the Zend Form Elements documentation.

Perforce Chronicle - Release: 2012.2/486814