Hello all,

I'm trying to automatically sanitize and reformat phone and fax
numbers, so I knocked these model methods together but Ican't seem to
get it working.

function formatPhoneNumbers()
{
        if(isset($this->data[$this->name]) && count($this->data[$this-
>name])) {
                $this->log('$this->data['.$this->name.'] is set and is not 
empty');
                foreach($this->data[$this->name] as $key => $value )
                {
                        if(strpos($key, 'phone') || strpos($key, 'fax')) {
                                $this->formatPhone($key);
                                $this->log("{$key} is being reformatted");
                        }
                }
        }
        else
        {
                $this->log('$this->data['.$this->name.'] is not set or is 
empty');
        }
        return true;
}

function formatPhone($field=null)
{
        if(isset($this->data[$this->name][$field]) && !empty($this-
>data[$this->name][$field])) {
                $this->data[$this->name][$field] = preg_replace('/[^0-9]/i', '',
$this->data[$this->name][$field]);
        }
        return true;
}

This is to be used for all forms, so I put the methods in AppModel and
call them with beforeValidate like so:

function beforeValidate()
{
        $this->formatPhoneNumbers();
        return true;
}

Unfortunately, when I run the form with some data (with fields such as
'daytime_phone', 'evening_phone', 'fax'), the form is repopulated with
the data without being reformatted and I get the following message
logged:

2007-04-15 12:20:09 Error: $this->data[Award] is not set or is empty

Any help would be greatly appreciated, I may have just overlooked
something.

Cheers;
Poncho


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to