mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX #3922 simon_w: Perform form validation after the clicked button has been set.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@79567 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0fffbb47d3
commit
301989d203
@ -200,38 +200,6 @@ class Form extends RequestHandler {
|
|||||||
// Populate the form
|
// Populate the form
|
||||||
$this->loadDataFrom($vars, true);
|
$this->loadDataFrom($vars, true);
|
||||||
|
|
||||||
// Validate the form
|
|
||||||
if(!$this->validate()) {
|
|
||||||
if(Director::is_ajax()) {
|
|
||||||
// Special case for legacy Validator.js implementation (assumes eval'ed javascript collected through FormResponse)
|
|
||||||
if($this->validator->getJavascriptValidationHandler() == 'prototype') {
|
|
||||||
return FormResponse::respond();
|
|
||||||
} else {
|
|
||||||
$acceptType = $request->getHeader('Accept');
|
|
||||||
if(strpos($acceptType, 'application/json') !== FALSE) {
|
|
||||||
// Send validation errors back as JSON with a flag at the start
|
|
||||||
$response = new HTTPResponse(Convert::array2json($this->validator->getErrors()));
|
|
||||||
$response->addHeader('Content-Type', 'application/json');
|
|
||||||
} else {
|
|
||||||
$this->setupFormErrors();
|
|
||||||
// Send the newly rendered form tag as HTML
|
|
||||||
$response = new HTTPResponse($this->forTemplate());
|
|
||||||
$response->addHeader('Content-Type', 'text/html');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if($this->getRedirectToFormOnValidationError()) {
|
|
||||||
if($pageURL = $request->getHeader('Referer')) {
|
|
||||||
return Director::redirect($pageURL . '#' . $this->FormName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Director::redirectBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Protection against CSRF attacks
|
// Protection against CSRF attacks
|
||||||
if($this->securityTokenEnabled()) {
|
if($this->securityTokenEnabled()) {
|
||||||
$securityID = Session::get('SecurityID');
|
$securityID = Session::get('SecurityID');
|
||||||
@ -267,7 +235,38 @@ class Form extends RequestHandler {
|
|||||||
if(isset($funcName)) {
|
if(isset($funcName)) {
|
||||||
$this->setButtonClicked($funcName);
|
$this->setButtonClicked($funcName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate the form
|
||||||
|
if(!$this->validate()) {
|
||||||
|
if(Director::is_ajax()) {
|
||||||
|
// Special case for legacy Validator.js implementation (assumes eval'ed javascript collected through FormResponse)
|
||||||
|
if($this->validator->getJavascriptValidationHandler() == 'prototype') {
|
||||||
|
return FormResponse::respond();
|
||||||
|
} else {
|
||||||
|
$acceptType = $request->getHeader('Accept');
|
||||||
|
if(strpos($acceptType, 'application/json') !== FALSE) {
|
||||||
|
// Send validation errors back as JSON with a flag at the start
|
||||||
|
$response = new HTTPResponse(Convert::array2json($this->validator->getErrors()));
|
||||||
|
$response->addHeader('Content-Type', 'application/json');
|
||||||
|
} else {
|
||||||
|
$this->setupFormErrors();
|
||||||
|
// Send the newly rendered form tag as HTML
|
||||||
|
$response = new HTTPResponse($this->forTemplate());
|
||||||
|
$response->addHeader('Content-Type', 'text/html');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if($this->getRedirectToFormOnValidationError()) {
|
||||||
|
if($pageURL = $request->getHeader('Referer')) {
|
||||||
|
return Director::redirect($pageURL . '#' . $this->FormName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Director::redirectBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// First, try a handler method on the controller
|
// First, try a handler method on the controller
|
||||||
if($this->controller->hasMethod($funcName)) {
|
if($this->controller->hasMethod($funcName)) {
|
||||||
return $this->controller->$funcName($vars, $this, $request);
|
return $this->controller->$funcName($vars, $this, $request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user