From ed9f8dcf1f84df4a98267c1be48c9f96c2212e48 Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Wed, 9 Oct 2013 23:27:56 +1100 Subject: [PATCH] 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. --- admin/code/CMSForm.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/admin/code/CMSForm.php b/admin/code/CMSForm.php index 52dcda0d1..f364ad4ff 100644 --- a/admin/code/CMSForm.php +++ b/admin/code/CMSForm.php @@ -28,9 +28,16 @@ class CMSForm extends Form { protected function getValidationErrorResponse() { $request = $this->getRequest(); $negotiator = $this->getResponseNegotiator(); + if($request->isAjax() && $negotiator) { - $negotiator->setResponse(new SS_HTTPResponse($this)); - return $negotiator->respond($request); + $this->setupFormErrors(); + $result = $this->forTemplate(); + + return $negotiator->respond($request, array( + 'CurrentForm' => function() use($result) { + return $result; + } + )); } else { return parent::getValidationErrorResponse(); }