mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Fix move loading Cookie data to before the logged user check to prevent 'sticky' user data
This commit is contained in:
parent
04a5257e40
commit
6c1a29e807
@ -98,6 +98,23 @@ class CommentForm extends Form
|
||||
|
||||
parent::__construct($controller, $name, $fields, $actions, $required);
|
||||
|
||||
// load any data from the cookies
|
||||
if ($data = Cookie::get('CommentsForm_UserData')) {
|
||||
$data = Convert::json2array($data);
|
||||
|
||||
$this->loadDataFrom(array(
|
||||
'Name' => isset($data['Name']) ? $data['Name'] : '',
|
||||
'URL' => isset($data['URL']) ? $data['URL'] : '',
|
||||
'Email' => isset($data['Email']) ? $data['Email'] : ''
|
||||
));
|
||||
|
||||
// allow previous value to fill if comment not stored in cookie (i.e. validation error)
|
||||
$prevComment = Cookie::get('CommentsForm_Comment');
|
||||
|
||||
if ($prevComment && $prevComment != '') {
|
||||
$this->loadDataFrom(array('Comment' => $prevComment));
|
||||
}
|
||||
}
|
||||
|
||||
// if the record exists load the extra required data
|
||||
if ($record = $controller->getOwnerRecord()) {
|
||||
@ -131,24 +148,6 @@ class CommentForm extends Form
|
||||
|
||||
// Set it so the user gets redirected back down to the form upon form fail
|
||||
$this->setRedirectToFormOnValidationError(true);
|
||||
|
||||
// load any data from the cookies
|
||||
if ($data = Cookie::get('CommentsForm_UserData')) {
|
||||
$data = Convert::json2array($data);
|
||||
|
||||
$this->loadDataFrom(array(
|
||||
'Name' => isset($data['Name']) ? $data['Name'] : '',
|
||||
'URL' => isset($data['URL']) ? $data['URL'] : '',
|
||||
'Email' => isset($data['Email']) ? $data['Email'] : ''
|
||||
));
|
||||
|
||||
// allow previous value to fill if comment not stored in cookie (i.e. validation error)
|
||||
$prevComment = Cookie::get('CommentsForm_Comment');
|
||||
|
||||
if ($prevComment && $prevComment != '') {
|
||||
$this->loadDataFrom(array('Comment' => $prevComment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user