Good morning.

Cake 1.1.8.3544, php 4.4.0 and apache 2.0.54 (Win32).

I've always used this steps for trimming the posted data, but actually
it doesn't seems to work anymore.

In the app/app_model.php I've added this function

   function beforeValidate(){
      parent::beforeValidate();

      //trimming whole data
      if(isset($this->data[$this->name])){
         $buff = $this->data[$this->name];
         foreach($buff as $index=>$elem){
            if(is_string($elem)) $buff[$index] = trim($elem);
         }
         $this->data[$this->name] = $buff;
      }
      return true;
   }

that as you can see, step through the posted data and trim them if are
strings.

So, when they pass to validation, if I have a VALID_NOT_EMPTY field, and
the user inputed only spaces, cake automatically raise an error.

A sample model is something like this

   function add(){
      ...
      if(isset($this->data)){
         if($this->Treasury->save($this->data)){
            ...

This method always worked but now, with 1.1.8 I was testing it and saw
that it wont work.

So putting some logs I saw that in the model::invalidFields() function
at line 1308[1] made a test. Just before this line, the $data variable
holds the originally posted data (not trimmed), and $this->data holds
the trimmed ones.

The $data is not empty, so the validation is finally made on the not
trimmed data. How can I do to set also the $data variable? I've tried
something like

   function beforeValidate(){
      parent::beforeValidate();

      //trimming whole data
      if(isset($this->data[$this->name])){
         $buff = $this->data[$this->name];
         foreach($buff as $index=>$elem){
            if(is_string($elem)) $buff[$index] = trim($elem);
         }
         $this->data[$this->name] = $buff;
         $data = $this->data;
      }

      return true;
   }

but it doesn't work. Maybe I miss something.

Sorry for the long post.

Thanks and bye
Davide

1. http://api.cakephp.org/model__php4_8php-source.html#l01308
-- 
By the power of Greyskull...

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to