There is this:
http://groups.google.co.uk/group/cake-php/browse_thread/thread/6257c749081c4adc/01514bd32d4055ab?lnk=gst&q=sanitize+beforeValidate&rnum=2&hl=en#01514bd32d4055ab
which gives a method you could work from. I have developed it a little
more since, so if that look useful let me know and I will paste up a
newer version somewhere. Ianh

On 15 Apr, 04:29, "Poncho" <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I'm trying to automaticallysanitizeand 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 withbeforeValidatelike so:
>
> functionbeforeValidate()
> {
>         $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