Re: QF multiple rows of elements
| From: | Daniel Kopp | Date: | Tue, 27 Apr 2004 13:28:36 +0000 |
| Subject: | Re: QF multiple rows of elements | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12163@lists.php.net to get a copy of this message | ||
Hi!
Wolfgang Annen wrote:
> I am trying to create a form for putting in data in line-oriented
> forms, e.g. in each row of my form the user puts in a date and an
> amount. Each row of the form ist treated as a group but the number
> of rows can vary.
>
> My problem is that the addGroup-method does not accept an array
> variable for all rows. So I have to define each row by a separate
> addGroup statement.
sorry - I do not really get that ... is your problem that in your
array there are more than 1 element with the same name?
> Here my short example code:
>
> $el[1] = &HTML_QuickForm::createElement('text', 'Datum', null,
> ''); $el[2] = &HTML_QuickForm::createElement('text',
> 'Betrag',
> null, '');
>
> $this->addGroup($el, 'row1', 'Zeile:', ' ');
>
> $el[1] = &HTML_QuickForm::createElement('text', 'Datum', null,
> ''); $el[2] = &HTML_QuickForm::createElement('text',
> 'Betrag',
> null, '');
>
> $this->addGroup($zeile, 'row2', 'Zeile:', ' ');
>
> I am sure, there exists a much more comfortable way for this, but
> I didn't find the solution.
I guess there was some typo because the second group added does add a
group $zeile which is not defined ...
why don't you create your Elementarray like this:
$el[]= ...
and give your "dates" a number ...
like:
$el[] = &HTML_QuickForm::createElement('text', 'Datum'.$i,
null,'');
$el[] = &HTML_QuickForm::createElement('text', 'Betrag'.$i,null,
'');
To get seperate rows you will need to use a renderer like ITStatic. I
am doing this with:
while($i<$max){
$el[] = &HTML_QuickForm::createElement('static', '','',
'<tr><td>design element');
$el[] = &HTML_QuickForm::createElement('text', 'Datum'.$i,
null,'');
$el[] = &HTML_QuickForm::createElement('text', 'Betrag'.$i,
null, '');
}
$this->addGroup($el, 'rows', '', '');
Then I can use 'rows' in my template
But I am not proud about this piece of code ...
I think ITStatic sounds like this is not what is supposed to be done
with it ... (this way I do not have the separation between code and
design anymore which is the main purpose of using templates)
regards
Daniel