Re: QuickForm - dynamically add/del form elements question

From: Date: Tue, 26 Aug 2003 13:25:26 +0000
Subject: Re: QuickForm - dynamically add/del form elements question
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-20557@lists.php.net to get a copy of this message
<stoffel@lucent.com> wrote : > > Hi all, > > I've found HTML_QuickForm in my search for a good tool to use as a > base for a Dynamic Data Entry project I'm working on in my copious > (ha!) spare time. I've gone over Keith Edmund's excellent tutorial on > QuickForm, which is why I'd like to use this package if at all > possible. > > Basically, I have a MySQL DB with a primary table and three secondary > tables. Each record can have zero or more references to it from any > of the three sub-tables. Think of it like the Music database given in > the MySQL & mSQL book from O'Reilly, though specific to my needs. > > So I'd like to have some way to allow the user who's adding data to > dynamically add Text fields (and Select fields eventually) to the data > entry form as they work. We are planning to add a "repeat" element someday in QuickForm. Along with the new Controller, it will make these tasks easier. For now, you have to handle it manually, by watching which request are done in the form. > I've got my basic test script up on: > > cotarium.org/AAS/john/test/QF-refs.php URL is not available for me. > but I'm running into a couple of stumbling blocks. > > 1. How can I bind a button to clear a specific text element? Esp > when the text element and button are in a group together? And > when I don't know how many items there will be in the group? If by clearing you mean set to empty string, then you will need to use javascript onclick event. Set it on your button by adding an onclick attribute. Eventually, make a function that takes the element to be cleared as parameter and have your button call that function. > 2. Now that I know how to do that part, how do I create/delete > arbitrary elements in a form? Basically, I'll just have a special > group (the base one probably) which allows you to add an new > element. Then each text element will have two buttons, one to > clear an entry, another to delete it. Though clearing could be > considered deleting of course! > > So far my code does allow me to create a number of entry fields, and I > can get back data from them all (which is farther than I got with > oohforms from phplib-7.2d) but I'm stumped on the button interaction > unfortunately. You are trying to do some datagrid stuff. This is rather complex to do, with or without QuickForm. QuickForm can help you there by dynamically generating the fields you need on demand. The tricky part will be to parse the request sent by the form. Have every button called differently. An idea could be to call them button[key], this way you can test if 'button' is set in $_POST and then catch the corresponding key to know which row to remove. I've done that for a shopping cart application. Good luck, Bertrand Mansion Mamasam

« previous php.pear.dev (#20557) next »