Re: FormBuilder linkNewValue issue

From: Date: Fri, 20 May 2005 17:09:18 +0000
Subject: Re: FormBuilder linkNewValue issue
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19312@lists.php.net to get a copy of this message
On 5/20/05, Alessandro Pasotti <ale.pas@tiscali.it> wrote: > Il 17:58, venerdì 20 maggio 2005, Justin Patrin ha scritto: > > 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, > > [...] > > > > > > > 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. > > > I don'use any custom validation, this is what happens: > > MainForm Sub Form > --------- --------- > id PK .... > user_id FK <--> id PK > > * I choose --New Value-- for user_id and fill in the subform, then fill main > form values and submit > * processForm starts and try to validate main form user_id which must be NOT > NULL, but now it's NULL since the Sub Form has not been processed yet > * validation fails Aha...you're the person using validateOnProcess aren't you? So this is the validate() method on your DO that's failing, right, not the QuickForm validation? > > > To make it work I had to posticipate validation of mainform _after_ subform > has been processed in the inner loop. This is only necessary in case of > linkNewValues have been entered. > > This way it works since validation of main form happens after PK "id" of sub > form has been defined (from the DB). > > I was just asking myself of a better way (I don't like to change the code in > processForm or subclass it). > Ok, I can see the problem here. The linkNewValueText is a string and the DO's validation is not validating that it's a number. I, for one, have never used validateOnProcess and have been just fine without it. However, I have fixed your problem in CVS. You have to change: if ($value === '') { to if ($value == $this->linkNewValueText && $tableFields[$field] & DB_DATAOBJECT_INT) { $value = 0; } elseif ($value === '') { This will fool the validation into validating it even though the new value is not in there yet. This is a better way (IMHO) to do this than moving the validation as no DB operations should go through if any validation fails. At least, this is my idea of it. If you update to the newest CVS be forwarned that I just changed the driver system (BC Break). Read the commit messages to see if you need to alter your code. -- Justin Patrin

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