BUGFIX ajshort: Ensure that CSRF security token settings are passed from parent controllers/forms into child forms.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@80225 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-06-27 08:48:42 +00:00
parent 86ccd8cb96
commit c0c72e4c53
2 changed files with 16 additions and 1 deletions

8
forms/Form.php Normal file → Executable file
View File

@ -147,7 +147,13 @@ class Form extends RequestHandler {
// Form error controls
$this->setupFormErrors();
$this->security = self::$default_security;
// Check if CSRF protection is enabled, either on the parent controller or from the default setting. Note that
// method_exists() is used as some controllers (e.g. GroupTest) do not always extend from Object.
if(method_exists($controller, 'securityTokenEnabled')) {
$this->security = $controller->securityTokenEnabled();
} else {
$this->security = self::$default_security;
}
}
static $url_handlers = array(

9
forms/FormField.php Normal file → Executable file
View File

@ -305,6 +305,15 @@ class FormField extends RequestHandler {
return $this->form;
}
/**
* Return TRUE if security token protection is enabled on the parent {@link Form}.
*
* @return bool
*/
public function securityTokenEnabled() {
return $this->getForm() && $this->getForm()->securityTokenEnabled();
}
/**
* Sets the error message to be displayed on the form field
* Set by php validation of the form