mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
initial tweaks to Form to better support use in template control blocks
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@50988 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
d21d2a07f9
commit
b6dbeec30d
@ -184,11 +184,12 @@ class Form extends ViewableData {
|
|||||||
$this->validator->removeValidation();
|
$this->validator->removeValidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the form's fields - used by the templates
|
* Generate extra special fields - namely the SecurityID field
|
||||||
* @return FieldSet The form fields
|
* @todo Is there anything wrong with putting this in __construct?
|
||||||
*/
|
*/
|
||||||
function Fields() {
|
protected function genExtraFields() {
|
||||||
if(!$this->securityTokenAdded && $this->securityTokenEnabled()) {
|
if(!$this->securityTokenAdded && $this->securityTokenEnabled()) {
|
||||||
if(Session::get('SecurityID')) {
|
if(Session::get('SecurityID')) {
|
||||||
$securityID = Session::get('SecurityID');
|
$securityID = Session::get('SecurityID');
|
||||||
@ -200,10 +201,29 @@ class Form extends ViewableData {
|
|||||||
$this->fields->push(new HiddenField('SecurityID', '', $securityID));
|
$this->fields->push(new HiddenField('SecurityID', '', $securityID));
|
||||||
$this->securityTokenAdded = true;
|
$this->securityTokenAdded = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the form's fields - used by the templates
|
||||||
|
* @return FieldSet The form fields
|
||||||
|
*/
|
||||||
|
function Fields() {
|
||||||
|
$this->genExtraFields();
|
||||||
return $this->fields;
|
return $this->fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a block of HTML containing all the hidden fields for this form.
|
||||||
|
* Useful when doing custom field layouts
|
||||||
|
*/
|
||||||
|
function HiddenFields() {
|
||||||
|
$output = "";
|
||||||
|
foreach($this->fields->dataFields() as $field) {
|
||||||
|
if($field instanceof HiddenField) $output .= $field->Field();
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for the form fields.
|
* Setter for the form fields.
|
||||||
*
|
*
|
||||||
@ -220,6 +240,7 @@ class Form extends ViewableData {
|
|||||||
* @return FormField
|
* @return FormField
|
||||||
*/
|
*/
|
||||||
function dataFieldByName($name) {
|
function dataFieldByName($name) {
|
||||||
|
$this->genExtraFields();
|
||||||
return $this->fields->dataFieldByName($name);
|
return $this->fields->dataFieldByName($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user