mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
5927bf2399
commit
b548ee6360
@ -12,6 +12,12 @@
|
||||
* recreate the form object upon form submission, without the use of a session, which would be too
|
||||
* 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
|
||||
* @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) {
|
||||
$vars = $request->requestVars();
|
||||
@ -625,7 +634,11 @@ class Form extends RequestHandlingData {
|
||||
/**
|
||||
* Processing that occurs before a form is executed.
|
||||
* 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(){
|
||||
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() {
|
||||
$dataFields = $this->fields->dataFields();
|
||||
@ -771,16 +791,28 @@ class Form extends RequestHandlingData {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2.3 Use resetField()
|
||||
*/
|
||||
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();
|
||||
if($dataFields){
|
||||
foreach($dataFields as $field) {
|
||||
if($dataFields) foreach($dataFields as $field) {
|
||||
if($field->Name()==$fieldName) {
|
||||
$field = $field->setValue($fieldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the given method on the given field.
|
||||
|
Loading…
x
Reference in New Issue
Block a user