Fix move loading Cookie data to before the logged user check to prevent 'sticky' user data

This commit is contained in:
Stephen McMahon 2018-10-05 11:17:21 +10:00
parent 04a5257e40
commit 6c1a29e807

View File

@ -98,6 +98,23 @@ class CommentForm extends Form
parent::__construct($controller, $name, $fields, $actions, $required); 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 the record exists load the extra required data
if ($record = $controller->getOwnerRecord()) { 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 // Set it so the user gets redirected back down to the form upon form fail
$this->setRedirectToFormOnValidationError(true); $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));
}
}
} }
/** /**