Re: QuickForm issue: problem with createElement and addGroup within a loop
| From: | Justin Patrin | Date: | Sat, 14 May 2005 00:06:30 +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-19200@lists.php.net to get a copy of this message | ||
On 5/13/05, Skyler Slade <jsslade@gmail.com> 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']){
You need:
$element = array();
right here.
> $element[] = $form2->createElement('text',
> 'first', 'First Name);
> $element[] = $form2->createElement('text',
> 'last', 'Last Name');
> $form->addGroup($element);
>
> $i++;
> } // while
And additionally, you're putting in a bunch of elements with the *same
name* here. These will show up in $_POST as one variable.
--
Justin Patrin