Skip to content

Commit

Permalink
BUG: Fix CMS forms with validation errors responding incorrectly.
Browse files Browse the repository at this point in the history
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
ajshort committed Oct 9, 2013
1 parent 55c6f35 commit ed9f8dc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions admin/code/CMSForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ed9f8dc

Please sign in to comment.