Re: Creating a custom form-table with HTML_QuickForm
| From: | Bertrand Mansion | Date: | Mon, 16 Feb 2004 17:00:29 +0000 |
| Subject: | Re: Creating a custom form-table with HTML_QuickForm | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10728@lists.php.net to get a copy of this message | ||
<jsbiff@weldingengineering.com> wrote :
> Bertrand Mansion wrote:
>
> ~ > Hi Jeff,
> |
> | Making this sort of element, let's call it a "repeat" element, is very
> | tricky as it requires you to handle the name of the elements inside the
> | element as well as the validation rules and probably other things I
> forget.
> |
> | I have started to work on such an element but due to lack of time this
> | weekend, I haven't implemented much.
> |
> | So, at the moment, I think all this could be handled by a loop that
> will add
> | the elements to your form, depending on a hidden value or the add button
> | value, or a session value.
> |
> | while () {
> | $el[0] =& HTML_QuickForm::createElement();
> | $el[1] =& HTML_QuickForm::createElement();
> | $form->addGroup($el, ...);
> | }
>
> Well, but. . . I was looking at the grouping functionality of QuickForm,
> and that isn't quite exactly what I want. Grouping allows you to 'group'
> elements together, but conceptually they aren't a table (even if the
> default renderer puts them in a table cell). As far as I can tell,
> the default renderer, at least, lays out the form by creating one column
> for labels, a second column for inputs, and possibly a third column for
> additional labels. Normally, it puts one element and it's label in one
> row, and then puts the next element and it's label in the next row. If
> you group them, it puts the elements together in one row/column. (That
> is, enclosed by one td element).
>
> I think, probably ideally, my table should span both columns of the
> 'outer' table, and define a table within itself that has the appropriate
> number of columns that I need. The only potential problem with this
> approach is that this may possibly cause the entire QuickForm to render
> kind of funny. I'm not sure. I think it'd be ok in most cases.
>
> I'm thinking something like, first the developer using this table would
> create the table:
>
> ~ $this->addElement('dataTable', array('column1'=>'element
> type',
> 'column2'=>'element type', 'column3'=>'element
> type'));
>
> Where the array argument for the dataTable element would be a list of
> columnName=>Element, where Element is a string representing the
> HTML_QuickForm element (e.g. the string you would pass to
> createElement() or addElement()). The one thing I haven't figured out
> about this scheme is how you pass the default values for the columns. .
> . I'll spend some time thinking about that. Anyhow this is just to give
> an idea of what I have in mind.
>
> Then, when the table goes to render itself, it would do something like:
>
> for( $x = 0, $x < $rows, $x++){
> ~ $output_str .= "<tr>\n ";
> ~ foreach($columns as $key=>$value){
> ~ $field = &HTML_QuickForm::createElement( $value, $key . "[$x]",
> ~ $args );
> ~ $output_str .= "<td>" . $field->toHtml() . "</td> ";
> ~ }
> ~ $output_str .= "</tr>\n";
> }
>
>
> Something like that. The thing I'm not sure about, is how this will
> interact with renderers and such. Like, for example, we never actually
> added the elements to the form, or added the elements to a group and
> then added the group to the form.
>
> I suppose, ultimately, I'd kind of like this dataTable element to act
> kind of like a group object. Maybe that's what I should research - how
> groups are implemented, and if I can make this a group object.
>
> Basically, I want this to be a container object for QuickForm elements,
> but other than groups, QuickForm doesn't have the concept of container
> objects.
Groups are the container object of QuickForm. It seems that your problem is
more related to layout.
I think that what you are trying to do can be done using groups and a
dedicated template. Even with the default renderer you can set a template
for a group. In your case, you could use a table. If you are using the
default renderer, have a look at :
http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-ren
derer-default.setgrouptemplate.php
and
http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-ren
derer-default.setgroupelementtemplate.php
BTW, there is no need to call toHtml() yourself, never, this is done
automatically by QuickForm when you call display() or by groups when they
have to render the elements that composes them.
HTH
Bertrand Mansion
Mamasam