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:
Will Rossiter 2009-04-30 23:01:28 +00:00 committed by Sam Minnee
parent 2c6ba80f8d
commit c5ffdd4ae7

View File

@ -85,6 +85,14 @@ class Form extends RequestHandler {
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;
/**
@ -182,8 +190,12 @@ class Form extends RequestHandler {
if(Director::is_ajax()) {
return FormResponse::respond();
} else {
Director::redirectBack();
return;
if($this->getRedirectToFormOnValidationError()) {
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());
}
/**
* 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
* and used the next time this form is displayed.