PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject_FormBuilder » Bug #2257

fb object passed to preGenerateForm is not 100% functional

Details

Submitted2004-08-31 03:16 UTC
Fromluciano at praga dot org dot ar
Assignedjustinpatrin
StatusClosed
PackageDB_DataObject_FormBuilder
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-08-31 03:16 UTC] luciano at praga dot org dot ar

Description:
------------
In function getForm in FormBuilder.php, the function preGenerateForm is called before the 'fb_' prefix variables conversion. As result the fb object methods can't work properly because they use var names whithout 'fb_' prefix and at this momment this vars does not exist.
Is there a formbuilder-dev specific list rather than pear-dev?, i don't send this stuff to pear-dev because i think suscribing to pear-dev is way to much for me and my time.

Reproduce code:
---------------
/* As example */
class foo extends DB_DataObject
{
...
function preGenerateForm(&$fb) {
$label = $fb->getFieldLabel('foobar');
/* at this point $label == 'Foobar', no mather if you define it or not in fb_FieldLabels array, because $fb->getFieldLabel() use $this->fieldLabel array to return the label, and fieldLabel array is not set at this point */
}
}

Expected result:
----------------
If there is no side efects reversing the order like this would be great(first do the vars prefix conversion, then call the functions):
function &getForm($action = false, $target = '_self', $formName = false, $method = 'post')
{
$badVars = array('selectDisplayFields', 'selectOrderFields');
foreach (get_object_vars($this) as $var => $value) {
if ($var[0] != '_' && !in_array($var, $badVars) && isset($this->_do->{'fb_'.$var})) {
$this->$var = $this->_do->{'fb_'.$var};
}
if (method_exists($this->_do, 'pregenerateform')) {
$this->_do->preGenerateForm($this);
}
}
/*rest of getForm*/

[2004-08-31 22:43 UTC] luciano at praga dot org dot ar

ok, let me put this in other way:
I need to make my own form, but i still want to use formbuilder->process and stuff...
<code>
class fooFrom extends HTML_QuickForm {
function fooForm(...)
{
parent::HTML_QuickForm(...);
require_once('DB/DataObject/FormBuilder.php');
$bar = DB_DataObject::factory('Indicador');
$fbuilder=& DB_DataObject_Formbuilder::create($bar);
/* for 'some_field' i need a simple select */
$opt = $fbuilder->getSelectOptions('some_field');
/* $opt works ok, now i have de select options */
$label = $fbuilder->getFieldLabel('some_field');
/* once again, this did not work cause fb_vars */
$this->addElement('select','bar', $label, $opt);
}
</code>
The point is, that is usefull to get a fbuilder object, and use it's methods to build your own form. I could made a hirselect very easy whit this methods, and steel keep Fields stuff in the class.
getFieldLabel is the only method i use and found trouble, but i think this need a policy rule for future methods using non fb_vars. Because if they are public methods, you will expect that all work ok, once you instasiate an object.
Once again all this is IMHO.