Permalink
Browse files

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.
  • Loading branch information...
1 parent 55c6f35 commit ed9f8dcf1f84df4a98267c1be48c9f96c2212e48 @ajshort ajshort committed Oct 9, 2013
Showing with 9 additions and 2 deletions.
  1. +9 −2 admin/code/CMSForm.php
View
11 admin/code/CMSForm.php
@@ -28,9 +28,16 @@ public function validate() {
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();
}

0 comments on commit ed9f8dc

Please sign in to comment.