hi,

The "problem" seems to be that the sfPropelForm updateObject() { ...
object -> fromArray($this -> getValues()) } overwrites all the fields
given in the widget / validator schema, as each key is present in the
getValues() array. -- removing the widget / validator for the
corresponding field avoids the problem. Is this the intended behavior?

POST:

Array
(
    [project] => Array
        (
            [title] => Foo
        )

)

public function executeCreate($request)
  {
    $project = new Project;
    $project -> setRandomField('Random text');
    $form = new ProjectForm($project);

    if ($request -> isMethod('post'))
    {
      $form -> bind($request -> getParameter('project'));

      if ($form -> isValid())
      {
        print_r($form -> getObject()); // [random_field:protected] =>
Random text
        $form -> save();
        print_r($form -> getObject()); // [random_field:protected] =>

2008/11/12 Fabien Potencier <[EMAIL PROTECTED]>
>
> When you create the form, you pass an object. This object have the
> user_id and type set. It those columns are not in the form, they won't
> be in the POST array, so then they won't change the object when you
> bind() then save() the form. i have just tested and it works.
>
> Fabien
>
> --
> Fabien Potencier
> Sensio CEO - symfony lead developer
> sensiolabs.com | symfony-project.com | aide-de-camp.org
> Tél: +33 1 40 99 80 80
>
>
> Dan Leech wrote:
> > hi fabien
> >
> > My use case is...
> >
> > Database record:
> >
> > report:
> >   title: varchar
> >   type: varchar
> >   scale: int
> >   theme: varchar
> >   user_id: int
> >
> > On the edit page I render the title, scale and theme fields in the form.
> > The type and user_id are not part of the form, and should not change.
> >
> > I instantiate the form with the current object, with the current values:
> >
> > $form = new ReportForm($current_record);
> >
> > I bind the form with the field subset given in the POST array. The
> > "user_id" and "type" fields are then null.
> >
> > cheers
> >
> > dan
> >
> > 2008/11/12 Fabien Potencier <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>>
> >
> >
> >
> >     Dan Leech wrote:
> >      > hi all
> >      >
> >      > i think the form framework is great, but .....
> >      >
> >      > When I bind a form to a request array the values in the object are
> >      > wiped, e.g. if I set the a user_id field before the bind, it is
> >     set to
> >      > null after. So any data that is in the record is wiped and
> >     replaced by
> >      > the data in the request array. Forcing me to add more lines of
> >     code to
> >      > add missing data into the bind-data or drop the 'required' validation
> >      > and populate the values in the updateObject method.
> >      >
> >      > Is this a bug or am I just wrong?
> >
> >     It is not a bug. A form has two state:
> >
> >       * A form with the default values
> >       * A bound form which is a form updated with the submitted values.
> >
> >     And it does not make sense to change the submitted values. To better
> >     answer your question, can you give us more information of your use case.
> >
> >     Fabien
> >
> >      >
> >      > cheers
> >      >
> >      > dan
> >      >
> >      >
> >      > --
> >      > Dan Leech
> >      >
> >      > Dynamic Web Sites
> >      > www.dantleech.com <http://www.dantleech.com>
> >     <http://www.dantleech.com>
> >      >
> >      > Bath Gigs
> >      > www.bathgigs.co.uk <http://www.bathgigs.co.uk>
> >     <http://www.bathgigs.co.uk>
> >      >
> >      > >
> >
> >
> >
> >
> >
> > --
> > Dan Leech
> >
> > Dynamic Web Sites
> > www.dantleech.com <http://www.dantleech.com>
> >
> > Bath Gigs
> > www.bathgigs.co.uk <http://www.bathgigs.co.uk>
> >
> > >
>
>
> >



--
Dan Leech

Dynamic Web Sites
www.dantleech.com

Bath Gigs
www.bathgigs.co.uk

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to