Re: DB_DataObject_FormBuilder : 1:many relation

From: Date: Tue, 19 Apr 2005 16:08:20 +0000
Subject: Re: DB_DataObject_FormBuilder : 1:many relation
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18798@lists.php.net to get a copy of this message
Hi Justin, I've downloaded your SubForm class at <http://fb.reversefold.com/SubForm.phps>. It's easy to create subForm with it, but how do you set up a link which hides / displays the subForm? Also, is it possible, with your subForm to add subForm "on demand". For instance, a DOCUMENT can have many AUTHORS, so I would like to have a DOCUMENT form with a link "add an author" which adds as many AUTHOR as we want. Thanks for your help. Thomas.
To do this with a SubForm, do the same as above but don't use useForm(). Instead, add en element to the document form which is of type subForm and pass in the author form. You may also want to make use of setPreValidationCallback() on the subform to make it not validate of nothing was entered. I also set up, in my form, a link which hides / displays the subForm and also sets a hidden value to '1' if the subForm is displayed so that the script knows to validate and enter a new record. I also set up a static element which displays a Structures_DataGrid filled out with all of the previously entered sub-records.
On 14 Apr 2005, at 19:39, Justin Patrin wrote:
On 4/14/05, Thomas Balthazar <tba@voxteneo.com> wrote:
Hi, I would like to manage a 1 to many relationship in one single form. Explanations : I have a DOCUMENTS table and a AUTHORS tables. A document can have multiple authors associated to it. An author can only be associated with one document. The DOCUMENTS primary key is DOC_ID (identity). AUTHORS has a foreign key to DOC_ID. I would like to be able to generate a form that allows me to fill in the values for a document and for the author at the same time . For instance : document title : ___ document description : ___ author name : ___ How can I generate such a form? I tried to use Nested forms, but I cannot figure out how I can tell the AUTHORS.DOC_ID field to be set to the newly inserted DOCUMENT.DOC_ID value. Am I clear? :o) Thanks in advance for your help.
Funny you should mention this now, this is exactly what I created my SubForm element to do. However, you can do it without the SubForm. 1) Create the Document form. 2) Create the Author form 2a) Use $fb->useForm() and pass in the Document form so that the author form will have the document form at the top 2b) Use elementNamePrefix to make sure that the field names don't clash 3) If form validates (is submitted) then run $form->process() on both of the formbuilder objects (once for the document and once for the author). 3a) Before processing for the author, set the document id in the dataobject you used to create the form (yes, it should still be the same object in the formbuilder ;-) ) To do this with a SubForm, do the same as above but don't use useForm(). Instead, add en element to the document form which is of type subForm and pass in the author form. You may also want to make use of setPreValidationCallback() on the subform to make it not validate of nothing was entered. I also set up, in my form, a link which hides / displays the subForm and also sets a hidden value to '1' if the subForm is displayed so that the script knows to validate and enter a new record. I also set up a static element which displays a Structures_DataGrid filled out with all of the previously entered sub-records. -- Justin Patrin -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


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