HTML_QuickForm: toArray overwrites radio-boxes with the same name
| From: | Michael Raidel | Date: | Sun, 12 Jan 2003 20:48:45 +0000 |
| Subject: | HTML_QuickForm: toArray overwrites radio-boxes with the same name | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-12298@lists.php.net to get a copy of this message | ||
Hello!
I had a little problem with HTML_QuickForm::toArray(): the function always "merged" elements with the same name (for example radiobuttons) which are not in a group. toHTML() has no problem with this elements. The reason for the problem is that the values are written in an associative array with the name of the element as the key.
So there are two possible solutions, first to use another key and second to split this elements in an array of arrays. I chose the second one with the following code in toArray() (a quick hack, not using PEAR coding standards ;-):
I would be interested in your opinion,
Michael
Original:
if (isset($currentSection)) {
$returnVal['sections'][$currentSection]['elements'][$name] =
array_merge(array('required'=>$this->isElementRequired($name)),
$element->toArray());
}
Changed Version:
if (isset($currentSection)) {
$content = array_merge(array('required'=>$this->isElementRequired($name)),$element->toArray());
if ($returnVal['sections'][$currentSection]['elements'][$name]) {
// just my first idea how to find out, if the array is filled with associative values
//(happens on the first element with an identical name)
if ($returnVal['sections'][$currentSection]['elements'][$name]["html"]) {
$val = $returnVal['sections'][$currentSection]['elements'][$name];
unset($returnVal['sections'][$currentSection]['elements'][$name]);
$returnVal['sections'][$currentSection]['elements'][$name] = array($val,$content);
} else {
array_push($returnVal['sections'][$currentSection]['elements'][$name], $content);
}
} else {
$returnVal['sections'][$currentSection]['elements'][$name] = $content;
}
}
// Of course the code would have to be changed in the non-section part of the code too in a final version..