2013-05-10 15:00:13 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Deals with special form handling in CMS, mainly around {@link PjaxResponseNegotiator}
|
|
|
|
*/
|
|
|
|
class CMSForm extends Form {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Route validation error responses through response negotiator,
|
|
|
|
* so they return the correct markup as expected by the requesting client.
|
|
|
|
*/
|
|
|
|
protected function getValidationErrorResponse() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$negotiator = $this->getResponseNegotiator();
|
|
|
|
if($request->isAjax() && $negotiator) {
|
|
|
|
$negotiator->setResponse(new SS_HTTPResponse($this));
|
|
|
|
return $negotiator->respond($request);
|
|
|
|
} else {
|
|
|
|
return parent::getValidationErrorResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the response negotiator
|
|
|
|
* @param ResponseNegotiator $negotiator The response negotiator to use
|
|
|
|
* @return Form The current form
|
|
|
|
*/
|
|
|
|
public function setResponseNegotiator($negotiator) {
|
|
|
|
$this->responseNegotiator = $negotiator;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current response negotiator
|
|
|
|
* @return ResponseNegotiator|null
|
|
|
|
*/
|
|
|
|
public function getResponseNegotiator() {
|
|
|
|
return $this->responseNegotiator;
|
|
|
|
}
|
|
|
|
|
2013-09-18 13:55:30 +02:00
|
|
|
public function FormName() {
|
|
|
|
if($this->htmlID) return $this->htmlID;
|
|
|
|
else return 'Form_' . str_replace(array('.', '/'), '', $this->name);
|
|
|
|
}
|
|
|
|
|
2013-05-10 15:00:13 +02:00
|
|
|
}
|