Re: FormBuilder linkNewValue issue
| From: | Justin Patrin | Date: | Fri, 20 May 2005 00:23:44 +0000 |
| Subject: | Re: FormBuilder linkNewValue issue | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19288@lists.php.net to get a copy of this message | ||
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.
If you're getting lots of DB errors I suggest you re-think how you're
entering data. If you're clashing on a UNIQUE field it's a really good
idea to add a QF formRule which checks to make sure that that field
(or set of fields) is unique. Granted, it is still possible for the
unique constraint to fail if two users submit the same data at the
same time, but this will avert 90%+ of unique constraint problems.
Also, this allows you to give a nice QF-friendly error message for the
field(s) which must be changed instead of a big DB error message which
says who knows what. This also has the added bonus that you don't do
*any* DB operations at all and the form itself doesn't validate.
Now all that said it *might* be possible to deal with linkNewValues
specially..however, due to the nature of the system, it will be hard
to do. The form is created before any processing happens and the
processing function has no way to access or change the form as you've
already been given it. This would make it impossible to alter the form
to select the correct value and hide the linkNewValue form (or to give
the linkNewValue form the correct record ID). linkNewValue forms are
simply not set up to edit records, only to insert them.
I suggest you combine the two methods I mentioned above. Check your
constraints in a formRule and also use transactions on the DO.
>
> Expected behaviour:
>
> there are two possibilities:
>
> 1 - kind of rollback on insertion of linked sub-forms when the main form fails
> 2 - set the sub-form hidden PK to the value of the last inserted row and set
> the main form linked field to the same value
>
>
> Any help would be higly appreciated.
>
--
Justin Patrin