Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.2

Bug #3124 frozen select options not displayed
Submitted: 2005-01-06 14:41 UTC Modified: 2006-12-16 02:24 UTC
From: andrew dot clark at ucsb dot edu Assigned: justinpatrin
Status: Closed Package: DB_DataObject_FormBuilder
PHP Version: 4.3.10 OS: FreeBSD
Roadmaps: (Not assigned)    
Subscription  


 [2005-01-06 14: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.

Comments

 [2005-01-06 15:11 UTC] justinpatrin
I am absolutely sure that frozen select boxes (including links and enums) show the right info, at least on my own home server with PHP 4.3.10, bleeding edge FB, and all PEAR packages upgraded (I just did an upgrade-all). I also have my preferred state set to beta, but I doubt that would make a difference. What version of HTML_QuickForm do you have installed? Have you made sure that the QF element actually has the right "value" (print_r on the element)? Does it work when not frozen? Could you provide a small example that demonstrates the problem?
 [2005-01-06 16: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 17:06 UTC] justinpatrin
So what you're saying is that it displays nothing, not even the first or default value? If this is the case, are you using a custom renderer? Have you altered the default renderer? Are you changing the renderer's template(s)? Are you using a template system? If the hidden field is displayed with the right value, I highly doubt that there's a bug in FB or QF. It sounds more like it's just not being rendered.
 [2005-01-06 17: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 17:39 UTC] justinpatrin
Strange... let me know if CVS works. If it doesn't, something's horribly wrong. On my test system it's working with an enum field... If it continues to not work, could you post some code showing how you're setting up the enum field? Are you using the default callback to get the options or have you defined your own? This could very easily be a problem with the prefix/postfix options. They're very new. I just recently did lots of testing and committed some fixes. Also, make sure there are no '[' or ']' in your prefix and postfix.
 [2005-01-06 17: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 18:43 UTC] justinpatrin
Is the enum set up as an extra field in a cross link?
 [2005-01-06 18: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-07 20:01 UTC] justinpatrin
So this enum field is being shown in a normal form as a normal field (not in crosslinks). Could you please post some code that shows this problem? Output of this SQL may also help: SHOW COLUMNS FROM net_contact LIKE role I don't think you ever mentioned. Are you using the Default renderer? Are you using Smarty, Flexy, etc.?
 [2005-01-11 15: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(); ?>
 [2005-01-12 23:12 UTC] justinpatrin
Well, I know for sure that enum fields work fine frozen in their own forms. I don't have the time right now to test your code. However, it doesn't seem to be freezing right when in a crosslink. Probably due to me using [ and ] in the prefix and postfix for the extra fields.
 [2005-01-13 14:42 UTC] justinpatrin
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. Well, sorry about that, I guess I was wrong. Some enums do have this problem (and some selects may as well). When HTML_QF is making the display value it uses == and a normal string == 0 (such as 0 == 'bc') so the value doesn't display. I've changed the selectAddEmpty option for enums to use '' as the array key instead of 0. Perhaps I should submit a QF bug...
 [2005-01-13 17:18 UTC] justinpatrin
I have submitted HTML_QuickForm bug #3193 in response to this issue.