mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCHEMENT: added ability for a form author to set whether user should be redirected back down the the form rather then just back to the old page
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75784 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2c6ba80f8d
commit
c5ffdd4ae7
@ -85,6 +85,14 @@ class Form extends RequestHandler {
|
|||||||
|
|
||||||
protected $messageType;
|
protected $messageType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should we redirect the user back down to the
|
||||||
|
* the form on validation errors rather then just the page
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $redirectToFormOnValidationError = false;
|
||||||
|
|
||||||
protected $security = true;
|
protected $security = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,8 +190,12 @@ class Form extends RequestHandler {
|
|||||||
if(Director::is_ajax()) {
|
if(Director::is_ajax()) {
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
} else {
|
} else {
|
||||||
Director::redirectBack();
|
if($this->getRedirectToFormOnValidationError()) {
|
||||||
return;
|
if($pageURL = $request->getHeader('Referer')) {
|
||||||
|
return Director::redirect($pageURL . '#' . $this->FormName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Director::redirectBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +260,27 @@ class Form extends RequestHandler {
|
|||||||
$this->transform(new ReadonlyTransformation());
|
$this->transform(new ReadonlyTransformation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the user should be redirected back down to the
|
||||||
|
* form on the page upon validation errors in the form or if
|
||||||
|
* they just need to redirect back to the page
|
||||||
|
*
|
||||||
|
* @param bool Redirect to the form
|
||||||
|
*/
|
||||||
|
public function setRedirectToFormOnValidationError($bool) {
|
||||||
|
$this->redirectToFormOnValidationError = $bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether the user should be redirected back down to the
|
||||||
|
* form on the page upon validation errors
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getRedirectToFormOnValidationError() {
|
||||||
|
return $this->redirectToFormOnValidationError;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an error message to a field on this form. It will be saved into the session
|
* Add an error message to a field on this form. It will be saved into the session
|
||||||
* and used the next time this form is displayed.
|
* and used the next time this form is displayed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user