Home » HTML » HTML_QuickForm » Bug #1740
Create Groups within groups
Details
| Request #1740 | Create Groups within groups |
|---|---|
| Submitted | 2004-06-29 23:43 UTC |
| From | tdr32 at cs dot byu dot edu |
| Status | Bogus |
| Package | HTML_QuickForm |
| PHP Version | 4.3.2 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2004-06-29 23:43 UTC] tdr32 at cs dot byu dot edu
Description:
------------
I have a form that allows users to delete and view comments given to them all in one page. Using Smarty as my template, I thought it would be much easier to just place all the comments in one array (pulled from MySQL), like this:
[comments] => Array
(
[0] => Array
(
[id] => 104
[comment] => aoeuaoethoaeu
[submitter] => Me
[datetime] => 20040603152421
)
[1] => Array
(
[id] => 106
[comment] => aoeunthaicr,atichaotjhic.
[submitter] => Me
[datetime] => 20040608112939
)
)
Then, I would build a group for comments that holds groups that contain all the comment data.
This way, with Smarty or any other renderer, I can just loop through the big group comment and then loop through each of the smaller groups inside.
I discovered that HTML_QuickForm doesn't like that, so I looked in the code of Array.php and ArraySmarty.php and changed the _currentGroup to be an array of groups instead of just one group array. I did this by changing in startGroup and finishGroup, I did array_unshift and array_shift and created a new variable(_currentGroupCount) to hold where we are in the array, meaning which inner group are we in. Then, everytime that _currentGroup is called, I just added on [_currentGroupCount] and it worked. And, amazingly, I didn't have to do any changes to how the defaults worked since it worked just perfectly.
Reproduce code:
---------------
In Array.php
function startGroup(&$group, $required, $error)
{
$this->_currentGroupCount = array_unshift($this->_currentGroup,$this->_elementToArray($group, $required, $error));
// arrays have an index from 0 not 1
$this->_currentGroupCount--;
if (!empty($error)) {
$this->_ary['errors'][$this->_currentGroup[$this->_currentGroupCount]['name']] = $error;
}
} // end func startGroup
function finishGroup(&$group)
{
$this->_storeArray($this->_currentGroup[$this->_currentGroupCount]);
array_shift($this->_currentGroup);
$this->_currentGroupCount--;
} // end func finishGroup
And everywhere in Array.php and ArraySmarty.php where _currentGroup is called I instead write $this->_currentGroup[$this->_currentGroupCount];
[2004-06-30 07:49 UTC] bmansion at mamasam dot com
Groups in groups are not supported by QuickForm.
In your special case, you don't need them anyway.