BUG: Fix CMS forms with validation errors responding incorrectly.

A new form instance was being constructed for the response, which mean
that a lot of the validation information was lost. This fix means that:

* Enterered data is correctly persisted.
* A validation error notification is displayed.
This commit is contained in:
Andrew Short 2013-10-09 23:27:56 +11:00
parent 55c6f35e15
commit ed9f8dcf1f

View File

@ -28,9 +28,16 @@ class CMSForm extends Form {
protected function getValidationErrorResponse() { protected function getValidationErrorResponse() {
$request = $this->getRequest(); $request = $this->getRequest();
$negotiator = $this->getResponseNegotiator(); $negotiator = $this->getResponseNegotiator();
if($request->isAjax() && $negotiator) { if($request->isAjax() && $negotiator) {
$negotiator->setResponse(new SS_HTTPResponse($this)); $this->setupFormErrors();
return $negotiator->respond($request); $result = $this->forTemplate();
return $negotiator->respond($request, array(
'CurrentForm' => function() use($result) {
return $result;
}
));
} else { } else {
return parent::getValidationErrorResponse(); return parent::getValidationErrorResponse();
} }