PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject_FormBuilder » Bug #3124

frozen select options not displayed

Details

Submitted2005-01-06 19:41 UTC
Fromandrew dot clark at ucsb dot edu
Assignedjustinpatrin
StatusClosed
PackageDB_DataObject_FormBuilder
PHP Version4.3.10
OSFreeBSD
Roadmaps(Not assigned)

Comments

[2005-01-06 19:41 UTC] andrew dot clark at ucsb dot edu

Description:
------------
Frozen select options (like enumFields) don't display their selected value(s). This might be a bug in QuickForm itself.

[2005-01-06 21:56 UTC] andrew dot clark at ucsb dot edu

I have QuickForm 3.2.4pl1 (installed via ports). A print_r of the form does show the value for that element:

[_values] => Array ( [0] => secondary )

There's hidden select element for that element with the proper value:

<input type="hidden" name="1eee4010bf7f28dcdea252b831fcc6d6role" value="secondary" /></td>

It does properly display when not frozen.
I should note I'm using elementNamePrefix in this form.

[2005-01-06 22:19 UTC] andrew dot clark at ucsb dot edu

It displays nothing. I'm not using a custom renderer, and further snooping shows that a select element created in preProcessForm, for instance, does properly display when frozen. This particular element that I'm using in enumFields will properly display when frozen if I define the element in preProcessForm like so:

function preGenerateForm(&$fb) {
$role_options = array(
'primary' => 'primary', 'secondary' => 'secondary',
'security' => 'security' , 'financial' => 'financial'
);

$this->fb_preDefElements['role'] =
HTML_QuickForm::createElement(
'select',
$fb->elementNamePrefix.'role'.$fb->elementNamePostfix,
'Role', $role_options
);
}

So it seems like it might be a bug in enumFields. I'm using DB_DataObject_FormBuilder 0.10.3, so I'll give CVS a go.

[2005-01-06 22:59 UTC] andrew dot clark at ucsb dot edu

It doesn't work with the latest CVS. Here's some background. I have a net_contact crosslinking table that links nets to contacts. Other than it's own id, the contact_id, net_id, and some datetime fields, it includes an extra field "role" which indicates the role that the contact has for that network. role is a MySQL enum with the following options at the moment:

enum('primary','secondary','security','financial')

The relevant DataObject code is as follows:

var $fb_enumFields = array('role');
var $fb_userEditableFields = array('role', 'last_verified');

There are no [ or ] in my [pre|post]fix (it's an md5 hash). Removing the prefix doesn't appear to make any difference.
I'm using the default enum callback.

[2005-01-06 23:49 UTC] andrew dot clark at ucsb dot edu

No. While the table containing the enum in question is a cross-linking table, it is not currently set up with crossLinks.

[2005-01-11 20:08 UTC] andrew dot clark at ucsb dot edu

Here's the column (pardon line wrapping):

mysql> show columns from net_contact like 'role';
+-------+----------------------------------------------------+------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------------------------------------------------+------+-----+-----------+-------+
| role | enum('primary','secondary','security','financial') | | | secondary | |
+-------+----------------------------------------------------+------+-----+-----------+-------+
1 row in set (0.01 sec)

I'm using the default renderer.
Here's the net_contact DO code (modified slightly, pardon the cruft still in the code):

<?php
/**
* Table Definition for net_contact
*/
require_once 'DB/DataObject.php';

class DataObjects_Net_contact extends DB_DataObject
{

###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */

var $__table = 'net_contact'; // table name
var $net_contact_id; // int(16) not_null primary_key unsigned
var $net_id; // int(16) not_null unsigned
var $contact_id; // int(16) not_null unsigned
var $role; // string(9) enum
var $last_modified; // timestamp(14) not_null unsigned zerofill timestamp
var $last_verified; // timestamp(14) not_null unsigned zerofill

/* ZE2 compatibility trick*/
function __clone() { return $this;}

/* Static get */
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Net_contact',$k,$v); }

/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE

var $fb_enumFields = array('role');
var $fb_dateFields = array('last_modified', 'last_verified');

var $fb_userEditableFields = array(
'role', 'last_verified','contact_id','net_id'
);

var $fb_fieldLabels = array(
'last_verified' => 'Last Verified',
'last_modified' => 'Last Modified',
'net_id' => 'Linked Net',
'contact_id' => 'Linked Contact',
);

var $fb_selectAddEmpty = array('role');

var $fb_crossLinkExtraFields = array('role');

function ident() {
$ident = false;

foreach ($this->keys() as $k) {
if ( isset($this->$k) ) {
$ident .= $k.$this->$k;
}
}

//return $ident === false ? false : md5(uniqid($ident));
return $ident === false ? false : md5($ident);
}

function format() {
return true;
}

function unformat() {
return true;
}

function insert() {
if (isset($this->last_modified)) {
unset($this->last_modified);
};
$this->unformat();
parent::insert();
}

function update($do = false) {
if (isset($this->last_modified)) {
unset($this->last_modified);
};
$this->unformat();
parent::update($do);
}

/*
// workaround for FormBuilder not showing frozen enums
function preGenerateForm(&$fb) {
$role_options = array(
null => null,
'primary' => 'primary', 'secondary' => 'secondary',
'security' => 'security' , 'financial' => 'financial'
);

$this->fb_preDefElements['role'] = HTML_QuickForm::createElement(
'select', $fb->elementNamePrefix .'role' .$fb->elementNamePostfix,
'Role', $role_options
);
}
*/

}

?>

and here's some code to display the problem:

<?php
require_once 'include/config.php';
require_once 'DB/DataObject/FormBuilder.php';

DB_DataObject::debugLevel(0);

$self =& DB_DataObject::factory('net_contact');

if (PEAR::isError($self)) {
die ( $self->getMessage() );
}

// FIXME case for tables with more than one key?
// in which cases do we actually need these?
$key = $self->keys();
$pk = $key[0];
$action = array();

if ( !empty($_GET[$pk]) ) {
if ( preg_match('/\d+/', $_GET[$pk]) ) {
// FIXME if get fails?
$self->get($_GET[$pk]) or die("No such id: $pk $_GET[$pk]");
}
array_push($action,"$pk=" .$self->$pk);
}

if (count($action) !== 0) {
$action = join("&",$action);
$action = $_SERVER['PHP_SELF'] ."?$action";
}

$builder =& DB_DataObject_FormBuilder::create($self);

// form
$fb_options = array( 'elementNamePrefix' => $self->ident(), );

$form =& $builder->getForm($action,$fb_options);

$form->freeze();

echo $form->toHtml();
?>