Re: Creating a custom form-table with HTML_QuickForm

From: Date: Mon, 16 Feb 2004 15:36:31 +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-10724@lists.php.net to get a copy of this message
<jsbiff@weldingengineering.com> wrote : > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello, > ~ Ok, I'm looking for a little bit of advice on how to approach a > particular problem. I want to create a sort of dynamic table with > embedded form elements. By dynamic, I mean I want to allow users to add > rows to the table. Picture it sort of like this: > > - ---------------------------------------------------- > | Input1a | Input2a | Input3a | Input4a | Input5a | > - ---------------------------------------------------- > > (buttons) > - ---------- ---------- > |Add Row | | Submit | > - ---------- ---------- > > If the user clicks the Add Row button, the current table gets returned > to the user's browswer along with an additional row of form inputs. > - ---------------------------------------------------- > | Input1a | Input2a | Input3a | Input4a | Input5a | > - ---------------------------------------------------- > | Input1b | Input2b | Input3b | Input4b | Input5b | > - ---------------------------------------------------- > > - ---------- ---------- > |Add Row | | Submit | > - ---------- ---------- > > ~ When I first started to tackle this project, I was going to use just > straight PHP. Then I thought "You know, I bet someone out there has a > package for being able to easily build complex forms using PHP code and > not having to do too much stuff by hand." So I started looking, and > that's how I found PEAR. Right now, I'm trying to figure out how best to > use PEAR's HTML facilities. > > ~ One option is to simply use HTML_QuickForm::createElement() to create > elements, but then generating the table myself in code that isn't > integrated very well with PEAR. With this option, anywhere I want to > place an element in my PHP code, I just call $element->toHtml(). > > ~ That approach would be fairly simple from a design standpoint, but it > doesn't seem to make very good use of, or work very well with, the > QuickForm package. For example, I'm not really sure that I'd be able to > integrate my generated form inside of a larger QuickForm very well. > > ~ I was looking at the HTML_QuickForm documentation and you guys have > the concept of a pseudo-element. I guess what I'm thinking would be the > preferable solution is if I can have this data-table be a pseudo-element > that could placed within a QuickForm (you'd end up with a > table-within-a-table, but it would be all one form then at least). > > ~ Does the idea of creating this as a new pseudo-element for QuickForm > seem appropriate? How would I get started creating a pseudo-element? If > so, and I can develop it, would you guys be interested in having me > submit it for consideration to be merged with the HTML_QuickForm package? 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, ...); } When the repeat element will be ready, it will be able to handle all that (and more) for you. Unfortunately, I can't give a date for that. If you have some ideas on how to implement such a "repeat" element or some feature requests, feel free to share them. Thx, Bertrand Mansion Mamasam

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