Re: FormBuilder linkNewValue issue

From: Date: Fri, 20 May 2005 15:58:09 +0000
Subject: Re: FormBuilder linkNewValue issue
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19306@lists.php.net to get a copy of this message
On 5/19/05, Alessandro Pasotti <ale.pas@tiscali.it> wrote: > Il 02:23, venerdì 20 maggio 2005, Justin Patrin ha scritto: > > On 5/19/05, Alessandro Pasotti <ale.pas@tiscali.it> wrote: > > > Hello, > > > > > > I have a big problem here: > > > > > > * I have a FB form with one linkNewValue linked table (PK on linked table > > > points to FK on main table) > > > * When there is an error in the main form, the linked new value in > > > sub-form is inserted correctly in the DB, but the form is displayed again > > > as nothing would happened in the sub form. > > > * When I correct the main form and submit it again, FB try to insert the > > > sub-form > > > values again and fails because DB constraints check for uniq in the > > > linked table. > > > > > > I don't know if this is a bug or I did'nt understand how it works. > > > > So basically you're getting a DB error on inserting the main record. > > How are you handling this? FB doesn't do any transactional stuff, so > > it can't really rollback. You could easily start a transaction before > > you process the FB and then roll it back if processForm returns an > > error. In fact, this is what I suggest you do. FB assumes that if the > > form validates it will process correctly. The DB processing is not > > fault tolerant at all. If something fails it's up to the calling app > > to deal with it. > > Thanks for the quick answer, I implemented commit/rollback stuff and now it > works great. > > I have another problem yet (the DB design is unfortunately not my choice): > > * Imagine you are adding a new record in the same scenario described above, > * When you call validation method _before_ the subform is processed it fails > because the required FK for the linked table is null. > * To make it work, I had to modify fb->processForm to posticipate validation > of the main form _after_ the subform is processed. > > Is there a more "elegant" solution for this problem? > I don't understand. What's failing? The linkNewValue value is "--New Value--" so it should pass the required rule. How exactly are you validating it? If you're using your own validation scheme, I suggest you check for the linkNewValue value. -- Justin Patrin

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