Re: Creating a custom form-table with HTML_QuickForm

From: Date: Mon, 16 Feb 2004 16:25:02 +0000
Subject: Re: Creating a custom form-table with HTML_QuickForm
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-10726@lists.php.net to get a copy of this message
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Before I go too far - should this discussion be taken to another list, or to private, off-list correspondence? Or is it ok to be on this list? Anyhow, since I'm sending this message I've include some comments below, interspersed with Bertrand's text. 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. :( Jeff Schmidt -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFAMO7c/djDnfAeGysRAtTzAJ9ELbysdaVhBsQ4z1w2B7Q9PdUGCACg25gv v/x/MxijT7baWmtN9J+tx3A= =4OW0 -----END PGP SIGNATURE-----

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