Re: QuickForm issue: problem with createElement and addGroup within a loop

From: Date: Sat, 14 May 2005 00:24:24 +0000
Subject: Re: QuickForm issue: problem with createElement and addGroup within a loop
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19201@lists.php.net to get a copy of this message
Skyler Slade wrote:
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']){
I guess you should put here: $element = array();
$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" />&nbsp;<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" />&nbsp;<input name="last" type="text" />&nbsp;<input name="first" type="text" />&nbsp;<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


« previous php.pear.general (#19201) next »