From edc29eddefb7a274f8e830ce735c600e9e685d7e Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 26 Nov 2008 01:20:31 +0000 Subject: [PATCH] BUGFIX: Fixed notice-level errors in PhoneNumberField git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@66707 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/PhoneNumberField.php | 49 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/forms/PhoneNumberField.php b/forms/PhoneNumberField.php index 9144f613c..567633aeb 100644 --- a/forms/PhoneNumberField.php +++ b/forms/PhoneNumberField.php @@ -1,4 +1,10 @@ ext = $extension; $this->countryCode = $countryCode; - parent::__construct( $name, ($title===null) ? $name : $title, $value, $form ); + parent::__construct( $name, $title, $value, $form ); } public function Field() { $field = new FieldGroup( $this->name ); $field->setID("{$this->name}_Holder"); - + + list( $countryCode, $areaCode, $phoneNumber, $extension ) = $this->parseValue(); $hasTitle = false; + + if ($this->value=="") + { + $countryCode=$this->countryCode; + $areaCode=$this->areaCode; + $extension=$this->ext; + } if( $this->countryCode !== null ) $field->push( new NumericField( $this->name.'[Country]', '+', $countryCode, 4 ) ); @@ -53,41 +67,42 @@ class PhoneNumberField extends FormField { public static function joinPhoneNumber( $value ) { if( is_array( $value ) ) { $completeNumber = ''; - - if( ! empty($value['Country']) ) + if( isset($value['Country']) && $value['Country']!=null) { $completeNumber .= '+' . $value['Country']; - - if( ! empty($value['Area']) ) + } + + if( isset($value['Area']) && $value['Area']!=null) { $completeNumber .= '(' . $value['Area'] . ')'; + } $completeNumber .= $value['Number']; - if( ! empty($value['Extension']) ) + if( isset($value['Extension']) && $value['Extension']!=null) { $completeNumber .= '#' . $value['Extension']; - + } + return $completeNumber; } else return $value; } protected function parseValue() { - - if( !is_array( $this->value ) ) + if( !is_array( $this->value )) preg_match( '/^(?:(?:\+(\d+))?\s*\((\d+)\))?\s*([0-9A-Za-z]*)\s*(?:[#]\s*(\d+))?$/', $this->value, $parts ); else return array( '', '', $this->value, '' ); - - if( is_array( $parts ) ) { - array_shift( $parts ); - $parts = array_pad($parts, 4, false); + + if(is_array($parts)) array_shift( $parts ); + + for ($x=0;$x<=3;$x++) { + if (!isset($parts[$x])) $parts[]=''; } - if(sizeof($parts) < 4) $parts[] = ''; - return $parts; } public function saveInto( $record ) { + list( $countryCode, $areaCode, $phoneNumber, $extension ) = $this->parseValue(); $fieldName = $this->name; @@ -103,7 +118,7 @@ class PhoneNumberField extends FormField { if( $extension ) $completeNumber .= '#' . $extension; - + $record->$fieldName = $completeNumber; }