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

Bug #351 Groups with default values seems off by one
Submitted: 2003-12-04 07:05 UTC
From: gmerrall at team dot aol7 dot cm dot au Assigned: avb
Status: Closed Package: HTML_QuickForm
PHP Version: 4.3.1 OS: Linux i386 (RedHat 8)
Roadmaps: (Not assigned)    
Subscription  


 [2003-12-04 07:05 UTC] gmerrall at team dot aol7 dot cm dot au
Description: ------------ Based on information from this thread http://marc.theaimsgroup.com/?t=106553837900001&r=1&w=2 When adding a number of groups of the same types, there appears to be an off-by-one error when assigning the defaults to the group. The first value always appears to be omitted. I can't explain it much better than that so I'll let the output do the talking. Let me know if you need more sample code Reproduce code: --------------- // the edit data comes from a database query foreach ($editdata as $row) { $defaults[$i] = array('user_name'=>$row['heading'], 'user_type'=>$row['type'], 'user_required'=>$row['required'], 'user_special'=>$row['special'] ); $i++; } for ($i=0; $i < $form_fields; $i++) { $fields = array(); $fields[] =& HTML_QuickForm::createElement('text', 'user_name', NULL); $fields[] =& HTML_QuickForm::createElement('select', 'user_type', NULL , $data); $fields[] =& HTML_QuickForm::createElement('advcheckbox', 'user_required', NULL, NULL, NULL, array('t','f')); $fields[] =& HTML_QuickForm::createElement('select', 'user_special', NULL, $specials); $form->addGroup($fields, $i, "Field $i"); } $form->addElement('submit', null, 'Send'); $form->setDefaults($defaults); $form->display(); Expected result: ---------------- Here's the default values array. [_defaultValues] => Array ( [0] => Array ( [user_name] => Field 1 [user_type] => text [user_required] => f [user_special] => email ) [1] => Array ( [user_name] => Field 2 [user_type] => radio [user_required] => t [user_special] => ) [2] => Array ( [user_name] => Field 3 [user_type] => check [user_required] => f [user_special] => ) [3] => Array ( [user_name] => Field 4 [user_type] => hidden [user_required] => t [user_special] => ) ) Actual result: -------------- Here's the first object from the first group. Note the default is empty. [_elements] => Array ( [0] => html_quickform_text Object ( [_attributes] => Array ( [name] => user_name [type] => text ) [_tabOffset] => 0 [_tab] => [_lineEnd] => [_comment] => [_label] => [_type] => text [_flagFrozen] => [_persistantFreeze] => 1 ) Here's the first object from the second group which has been correctly populated with the default value. [_elements] => Array ( [0] => html_quickform_text Object ( [_attributes] => Array ( [name] => user_name [type] => text [value] => Field 2 ) [_tabOffset] => 0 [_tab] => [_lineEnd] => [_comment] => [_label] => [_type] => text [_flagFrozen] => [_persistantFreeze] => 1 )

Comments

 [2003-12-09 12:19 UTC] avb
The bug is fixed in CVS. Nonetheless, consider *not* using purely numeric names for elements. This can give all kinds of weird behaviour.