1
votes

I have a problem and don't really know where to look for the cause of it. I have a propel form that is created basing on an object. The object is not empty:

$form = ModelNameForm($modelObject);

then I do binding with the request data:

$form->bind(
  $request->getParameter($form->getName()), 
  $request->getFiles($form->getName())
);

validate:

$form->isValid();

and finally save:

$result = $form->save();

The thing is that after binding the $form->getObject() returns the initial object although the $request->getParameter($form->getName()) contains correct values. What's more interesting is that after $form->save() the $form->getObject() gets the right values. The cause of it can be in the code but I don't have a clue where to look for it. Under what circumstances the form object may contain the old data after binding but show the new when I do var_dump after saving?

2

2 Answers

3
votes

This is the expected behavior of an sfForm. When you bind tainted values to the form its contained object won't know anything about those new values until you save the form. Binding allows you to validate the form, and if validation passes then you pass those new values into the object by calling $form->save(). I would suggest reading the symfony 1.4 Forms guide here: http://www.symfony-project.org/forms/1_4/en/

1
votes

I can't explain why (i use symfony for few weeks), but i had the same problem and i fixed it like that :

$result = $form->save();
$result->save();