From 5d6a4df1831702890437223221e90dd030380b05 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 19 Nov 2007 01:12:35 +0000 Subject: [PATCH] parents-merge 33066 - Improved support for decimal/currency saving git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45038 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/fieldtypes/Decimal.php | 9 +++++++++ forms/CurrencyField.php | 4 ++-- forms/Form.php | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/model/fieldtypes/Decimal.php b/core/model/fieldtypes/Decimal.php index b7554a581..fba5befff 100644 --- a/core/model/fieldtypes/Decimal.php +++ b/core/model/fieldtypes/Decimal.php @@ -24,6 +24,15 @@ class Decimal extends DBField { function requireField() { DB::requireField($this->tableName, $this->name, "decimal($this->wholeSize,$this->decimalSize)"); + } + + function saveInto() { + $fieldName = $this->name; + if($fieldName) { + $dataObject->$fieldName = (float)preg_replace('/[^0-9.]/', '', $this->value); + } else { + user_error("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object", E_USER_ERROR); + } } } diff --git a/forms/CurrencyField.php b/forms/CurrencyField.php index 6f43c630d..9ce62fc44 100755 --- a/forms/CurrencyField.php +++ b/forms/CurrencyField.php @@ -15,7 +15,7 @@ class CurrencyField extends TextField { */ function dataValue() { if($this->value){ - return ereg_replace('[^0-9.]',"", $this->value); + return preg_replace('/[^0-9.]/',"", $this->value); }else{ return 0.00; } @@ -82,7 +82,7 @@ class CurrencyField_Readonly extends ReadonlyField{ function Field() { if($this->value){ $val = $this->dontEscape ? ($this->reserveNL?Convert::raw2xml($this->value):$this->value) : Convert::raw2xml($this->value); - $val = '$' . number_format(ereg_replace('[^0-9.]',"",$val), 2); + $val = '$' . number_format(preg_replace('/[^0-9.]/',"",$val), 2); }else { $val = '$0.00'; diff --git a/forms/Form.php b/forms/Form.php index e16900783..e4336ae53 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -538,7 +538,7 @@ class Form extends ViewableData { if($field->Name() == "ClassName"){ $lastField = $field; }else if( $dataObject->hasMethod( $saveMethod ) ){ - $dataObject->$saveMethod( $field->Value()); + $dataObject->$saveMethod( $field->dataValue()); } else if($field->Name() != "ID"){ $field->saveInto($dataObject); }