Re: FormBuilder and update with frozen fields
| From: | Justin Patrin | Date: | Thu, 13 Oct 2005 16:19:26 +0000 |
| Subject: | Re: FormBuilder and update with frozen fields | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21451@lists.php.net to get a copy of this message | ||
On 10/13/05, Alessandro Pasotti <ale.pas@tiscali.it> wrote:
> Il 22:11, mercoledì 12 ottobre 2005, Justin Patrin ha scritto:
> > On 10/12/05, Alessandro Pasotti <ale.pas@tiscali.it> wrote:
> > > Hello,
> > >
> > > I saw a similar post with frozen dates, but cannot solve my problem,
> > >
> > > It seems that frozen fields (excluded from userEditableFields) are
> > > rendered as HIDDEN values, these are hence passed to the form.
> > >
> >
> > This is normal behavior for DB_DO. FormBuilder does *not* set the
> > values of frozen (non-editable) fields to the DO. They are set when
> > you fetch. However, DB_DO always sends all fields in an UPDATE call if
> > a DO is not provided in the update() call.
>
> This is the problem, DO contains all old fiels set (by me, see later), then
> FormBuilder correctly overwrite them (if not frozen), but _do->update()
> receives all the fields (old and overwrited new), hence update all.
update() doesn't "receive" fields as such. DO will check the field
values vs the old ones.
>
> >
> > However, FormBuilder *is* set up to only update what has been updated
> > by passing in the original DO to the update() call. Are you using the
> > newest version of FormBuilder?
>
> @version $Id: FormBuilder.php,v 1.204 2005/08/23 20:54:18 justinpatrin Exp
> $
>
> > Are you setting the DO correctly on
> > submission?
>
> This is maybe the issue, if an $id is passed (I always set an hidden id in the
> form), I always call $do->get($id) and populate the object, this seems
> necessary if the update fails and I want to redisplay the form with errors (I
> do some other processing with this $id, to get more detailed error info).
Yes, the $do has to be populated for the form to work properly. The
validation / display of errors should work fine as long as you're
following the normal validate()/display() algorithm.
>
> > How do you know that the query contains everything?
>
> I print all the queries, overriding DO _query().
>
First off, try overriding update like so:
function update(&$do) {
foreach ($this->table() as $field => $type) {
echo $field.' '.$this->$field.' '.$do->$field.'<br/>';
}
exit;
}
Then see what it outputs.
--
Justin Patrin