QuickForm issue: problem with createElement and addGroup within a loop
| From: | Skyler Slade | Date: | Fri, 13 May 2005 22:37:27 +0000 |
| Subject: | QuickForm issue: problem with createElement and addGroup within a loop | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-19199@lists.php.net to get a copy of this message | ||
Hi all,
I'm running into an issue with HTML_QuickForm. The problem arrises
when I attempt to use createElement() and addGroup() within a while
loop.
Within the while loop I have two text fields next to each other (first
name, last name) and the group should be added for each iteration of
$i (num of people in db), and it always seems to output 2, then 4,
then 6 (exponentially) as $i increases.
This might be better explained via code:
PHP:
-------------------------------------------
$name_num = 2;
$i = 0;
while($i < $HTTP_POST_VARS['name_num']){
$element[] = $form2->createElement('text', 'first', 'First Name);
$element[] = $form2->createElement('text', 'last', 'Last Name');
$form->addGroup($element);
$i++;
} // while
------------------------------------------
The input fields that it outputs looks like this:
[ ] [ ] (this is correct)
[ ] [ ] [ ] [ ] (fields have been doubled)
The output HTML is:
-------------------------------------------
<table border="0">
<tr>
<td align="right" valign="top"><b></b></td>
<td valign="top" align="left"><input name="first"
type="text"
/> <input name="last" type="text" /></td>
</tr>
<tr>
<td align="right" valign="top"><b></b></td>
<td valign="top" align="left"><input name="first"
type="text"
/> <input name="last" type="text" /> <input
name="first"
type="text" /> <input name="last" type="text"
/></td>
</tr>
-------------------------------------------
So long as I don't group the first name and last name elements, the
output is as it should be. However, when I try to add the names as a
group, that's when the output gets all funky. Am I doint something
wrong, or is this a bug?
Thanks,
-Skyler