API CHANGE Deprecated Form->resetData() - use Form->resetField()

ENHANCEMENT Added Form->resetField()
MINOR Documentation for Form

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63468 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-10-01 18:32:10 +00:00
parent 5927bf2399
commit b548ee6360

View File

@ -11,6 +11,12 @@
* can be passed using the URL or get variables. These restrictions are in place so that we can * can be passed using the URL or get variables. These restrictions are in place so that we can
* recreate the form object upon form submission, without the use of a session, which would be too * recreate the form object upon form submission, without the use of a session, which would be too
* resource-intensive. * resource-intensive.
*
* You will need to create at least one method for processing the submission (through {@link FormAction}).
* This method will be passed two parameters: the raw request data, and the form object.
* Usually you want to save data into a {@link DataObject} by using {@link saveInto()}.
* If you want to process the submitted data in any way, please use {@link getData()} rather than
* the raw request data.
* *
* @package forms * @package forms
* @subpackage core * @subpackage core
@ -135,7 +141,10 @@ class Form extends RequestHandlingData {
); );
/** /**
* Handle a form submission. GET and POST requests behave identically * Handle a form submission. GET and POST requests behave identically.
* Populates the form with {@link loadDataFrom()}, calls {@link validate()},
* and only triggers the requested form action/method
* if the form is valid.
*/ */
function httpSubmission($request) { function httpSubmission($request) {
$vars = $request->requestVars(); $vars = $request->requestVars();
@ -625,7 +634,11 @@ class Form extends RequestHandlingData {
/** /**
* Processing that occurs before a form is executed. * Processing that occurs before a form is executed.
* This includes form validation, if it fails, we redirect back * This includes form validation, if it fails, we redirect back
* to the form with appropriate error messages * to the form with appropriate error messages.
* Triggered through {@link httpSubmission()} which is triggered
* @usedby Form->httpSubmission()
*
* @todo Replace hardcoded exclude fields like CreditCardNumber with hook to specify sensitive fields in model
*/ */
function validate(){ function validate(){
if($this->validator){ if($this->validator){
@ -757,7 +770,14 @@ class Form extends RequestHandlingData {
} }
/** /**
* Get the data from this form * Get the submitted data from this form through
* {@link FieldSet->dataFields()}, which filters out
* any form-specific data like form-actions.
* Calls {@link FormField->dataValue()} on each field,
* which returns a value suitable for insertion into a DataObject
* property.
*
* @return array
*/ */
function getData() { function getData() {
$dataFields = $this->fields->dataFields(); $dataFields = $this->fields->dataFields();
@ -771,15 +791,27 @@ class Form extends RequestHandlingData {
return $data; return $data;
} }
/**
* @deprecated 2.3 Use resetField()
*/
function resetData($fieldName, $fieldValue){ function resetData($fieldName, $fieldValue){
return $this->resetField($fieldName, $fieldValue);
}
/**
* Resets a specific field to its passed default value.
* Does NOT clear out all submitted data in the form.
*
* @param string $fieldName
* @param mixed $fieldValue
*/
function resetField($fieldName, $fieldValue = null) {
$dataFields = $this->fields->dataFields(); $dataFields = $this->fields->dataFields();
if($dataFields){ if($dataFields) foreach($dataFields as $field) {
foreach($dataFields as $field) { if($field->Name()==$fieldName) {
if($field->Name()==$fieldName) { $field = $field->setValue($fieldValue);
$field = $field->setValue($fieldValue);
}
} }
} }
} }
/** /**