OnLoadListeners will be called on the first rendering of the form but not on postbacks. I didn't notice this for 2 years.
If you have a form displaying some initial values, those won't be filled in again when the form is dropped back after submit. What's filled in is what the user submits. 99% of the time this is not a problem and it isn't noticable at all. However, if you display some field values (outside inputs), those will be empty after posting the form.
Imagine the following form:
Name: <input name="name">
E-mail: {$email}
Example1: <input name="example1">
Example2: <input name="example2">
Notice we are simply displaying $email thus there is no <input> for it. When you post the form and it's dropped back, $email will be empty.
This is simply because OnLoadListeners are not called again on PostBack. You can't use OnPostBackListeners either, because those are called
after the $_POST values get filled in, thus onPostBackListeners would overwrite $_POST values.
You need to replace two functions in framework/controller/form.inc.php to get onLoadListeners called on postbacks also:
class FormController
{...
function postBackRestore
(&
$request, &
$responseModel) { // form postback fix START $responseModel->
merge($request->
exportPostProperties());
// form postback fix END } function dispatchEvents
(&
$request, &
$responseModel) { if ($this->
isPostback($request)) { // form postback fix START $view =
$this->
triggerEvent($this->
onLoadListeners,
array(&
$this, &
$request, &
$responseModel));
if (is_null($view)) { // form postback fix END $this->
postBackRestore($request,
$responseModel);
$view =
$this->
triggerEvent($this->
onPostBackListeners,
array(&
$this, &
$request, &
$responseModel));
if (is_null($view)) { foreach( array_keys($this->
rules) as $key) { Handle::
resolve($this->
rules[$key]);
$responseModel->
applyRule($this->
rules[$key]);
} $view =
$this->
dispatchChild($request,
$responseModel);
} // form postback fix START } // form postback fix END } else { $view =
$this->
triggerEvent($this->
onLoadListeners,
array(&
$this, &
$request, &
$responseModel));
} return $view;
}...
}
Update:
Two additional comments on this:
1. you could use hidden inputs instead
2. there are commits in the CVS following the 0.2a release, those might also help
In my case it was easier to apply the patch above.