mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #1082 from sminnee/form-improvements
Form improvements
This commit is contained in:
commit
e7e6c45aee
@ -982,9 +982,7 @@ class Form extends RequestHandler {
|
||||
*/
|
||||
public function Message() {
|
||||
$this->getMessageFromSession();
|
||||
$message = $this->message;
|
||||
$this->clearMessage();
|
||||
return $message;
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1001,8 +999,6 @@ class Form extends RequestHandler {
|
||||
}else{
|
||||
$this->message = Session::get("FormInfo.{$this->FormName()}.formError.message");
|
||||
$this->messageType = Session::get("FormInfo.{$this->FormName()}.formError.type");
|
||||
|
||||
Session::clear("FormInfo.{$this->FormName()}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1038,9 +1034,11 @@ class Form extends RequestHandler {
|
||||
$this->message = null;
|
||||
Session::clear("FormInfo.{$this->FormName()}.errors");
|
||||
Session::clear("FormInfo.{$this->FormName()}.formError");
|
||||
Session::clear("FormInfo.{$this->FormName()}.data");
|
||||
}
|
||||
public function resetValidation() {
|
||||
Session::clear("FormInfo.{$this->FormName()}.errors");
|
||||
Session::clear("FormInfo.{$this->FormName()}.data");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1325,6 +1323,13 @@ class Form extends RequestHandler {
|
||||
(array)$this->getTemplate(),
|
||||
array('Form')
|
||||
));
|
||||
|
||||
// Now that we're rendered, clear message
|
||||
Session::clear("FormInfo.{$this->FormName()}.errors");
|
||||
Session::clear("FormInfo.{$this->FormName()}.formError");
|
||||
Session::clear("FormInfo.{$this->FormName()}.data");
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,10 +11,43 @@ class ReadonlyField extends FormField {
|
||||
|
||||
protected $readonly = true;
|
||||
|
||||
/**
|
||||
* Include a hidden field in the HTML for the readonly field
|
||||
* @var boolean
|
||||
*/
|
||||
protected $includeHiddenField = false;
|
||||
|
||||
/**
|
||||
* If true, a hidden field will be included in the HTML for the readonly field.
|
||||
*
|
||||
* This can be useful if you need to pass the data through on the form submission, as
|
||||
* long as it's okay than an attacker could change the data before it's submitted.
|
||||
*
|
||||
* This is disabled by default as it can introduce security holes if the data is not
|
||||
* allowed to be modified by the user.
|
||||
*
|
||||
* @param boolean $includeHiddenField
|
||||
*/
|
||||
public function setIncludeHiddenField($includeHiddenField) {
|
||||
$this->includeHiddenField = $includeHiddenField;
|
||||
}
|
||||
|
||||
public function performReadonlyTransformation() {
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
public function Field($properties = array()) {
|
||||
// Include a hidden field in the HTML
|
||||
if($this->includeHiddenField && $this->readonly) {
|
||||
$hidden = clone $this;
|
||||
$hidden->setReadonly(false);
|
||||
return parent::Field($properties) . $hidden->Field($properties);
|
||||
|
||||
} else {
|
||||
return parent::Field($properties);
|
||||
}
|
||||
}
|
||||
|
||||
public function Value() {
|
||||
if($this->value) return $this->dontEscape ? $this->value : Convert::raw2xml($this->value);
|
||||
else return '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
|
||||
@ -25,7 +58,7 @@ class ReadonlyField extends FormField {
|
||||
parent::getAttributes(),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'value' => null,
|
||||
'value' => $this->readonly ? null : $this->value,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user