[TYPO3-ect] Draft of a form bean class

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Fri Aug 4 20:01:24 CEST 2006


Hello,

in the todays IRC Chat we were talking about the forms library. This is a
draft that describes the API a form "bean" that is able to

* be extended to build the actual form
* render the form XHTML
* render error messages
* preset default values for empty forms
* receive the  incoming parameters
* validate the incoming parameters
* to persistantly keep the parameters between requests until all
validations are passed
* implement the Simple PHP Library (SPL) API


// the class: SPL for PHP4
tx_forms_bean extends tx_lib_data

// preset values from external
tx_forms_bean->set($key, $value);

// get the values by the model
$value = tx_forms_bean->get($key);

// receive the incoming form parameters directly
tx_forms_bean->receive();

// receive the incoming form parameters from a controller
tx_forms_bean->receive($parameters);

// serializes the bean to the session
tx_forms_bean->store();

// unserializes the beam from the session
tx_forms_bean->load();

// validation
tx_forms_bean->validate();

// renders the XHTML output and error messages when needed
$out = tx_forms_bean->render();


Some of the methods must be implementated by the inherited form bean like
validate, render, .... Usually you make use of the validator and the forms
elements provided with this library.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Mark the technik with the persistant form data object, stored within the
session. This technic is seldom used within TYPO3 but gives us a behaviour
wich is most similiar to classical MVC programms.

This way the form and it's validation can be easiley treated as a unit,
although form display and validation happen in two different HTML requests.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

In many cases the model expects other values then the plain form
parameters. A good exampel is a unix timestamp. The form uses human
readable dates. There are 2 possibilities to transform this.

a) There are build in transformations for the get-Function. The timestamp
could be called as $time = tx_forms_bean->get('unixdate');

b) The form bean exports the plain parmaters and an adapter class makes the
transformations for the model. Here we make advantage of the SPL API.

Simplefied the concept is this. (It must be modified to match the TYP3
Coding guidlines).

   new model(new adapter($theFormBeam)));

This works because each of the objects data can be traversed by it's SPL API.


Elmar










More information about the TYPO3-team-extension-coordination mailing list