Re: QuickForm - dynamically add/del form elements question
| From: | John Stoffel | Date: | Tue, 26 Aug 2003 20:48:13 +0000 |
| Subject: | Re: QuickForm - dynamically add/del form elements question | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-20578@lists.php.net to get a copy of this message | ||
Bertrand> We are planning to add a "repeat" element someday in
Bertrand> QuickForm. Along with the new Controller, it will make these
Bertrand> tasks easier. For now, you have to handle it manually, by
Bertrand> watching which request are done in the form.
Ok, do you have any pointers on how I would do this?
>> I've got my basic test script up on:
>>
>> cotarium.org/AAS/john/test/QF-refs.php
Bertrand> URL is not available for me.
http://jfs.ecotarium.org/AAS/john/test/QF-refs.php
Hmmm... this works for me from a couple of different places. Can you
give me the IP address you're coming from? I'll check the logs and see
what's up.
>> 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?
Bertrand> If by clearing you mean set to empty string, then you will
Bertrand> need to use javascript onclick event. Set it on your button
Bertrand> by adding an onclick attribute. Eventually, make a function
Bertrand> that takes the element to be cleared as parameter and have
Bertrand> your button call that function.
Thanks for the hint, I'll do this since I've seen some examples of
this already and it should be easy to do.
>> 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.
Bertrand> You are trying to do some datagrid stuff. This is rather
Bertrand> complex to do, with or without QuickForm. QuickForm can help
Bertrand> you there by dynamically generating the fields you need on
Bertrand> demand.
Can QuickForm allow me to dynamically delete entries? Or do I need to
download, install and learn the datagrid package too? Sigh... the web
is not designed for data entry tasks, really.
Bertrand> The tricky part will be to parse the request sent by
Bertrand> the form. Have every button called differently. An idea
Bertrand> could be to call them button[key], this way you can test if
Bertrand> 'button' is set in $_POST and then catch the corresponding
Bertrand> key to know which row to remove.
I think I'm partly there in my app, though it's not completely clear
where I'm going wrong. The output of my script currently gives me the
following:
Found Sub-values for ref...
0=John
1=Bob
Found Sub-values for refgrp...
f0=David
f1=Tom
btnSubmit=Submit
So I think I'm almost there. It's the dynamically adding/deleting
elements that will mess me up I think.
I'll keep plugging away at this and let you know how it goes. I might
just punt on the single page form and just re-generate the form each
time they want to add in new elements. I'll worry about deleting them
later, since a "clear" button should work.
Thanks for your help!
John
stoffel@lucent.com