I'm getting a strange behaviour using the beforeValidate() callback. The
goal is to trim the required (VALID_NOT_EMPTY) fields before passing the
the cake validation.

It's strange 'cause it seems that if I put all correct data I get the
$this->data variable full of datas, otherwise if I leave a field that
doesn't pass the validation, in the beforeValidate() I get an empty
$this->data.

Following the model codes and the log traces.

Thanks and bye
Davide

//////////////////////
// This is the model
<?php
class User extends AppModel{
        var $name="User";
   var $belongsTo = array("State");
   var $validate = array(
                        "name"      => VALID_NOT_EMPTY,
                        "surname"   => VALID_NOT_EMPTY,
                        "birth"     => VALID_NOT_EMPTY,
                        "email"     => VALID_EMAIL
                   );

   function beforeValidate(){
      $this->log("beforeValidate()",LOG_DEBUG);
      $this->log($this->data,LOG_DEBUG);
      return true;
   }

   function beforeSave(){
      $this->log("beforeSave()",LOG_DEBUG);
      return true;
   }
}
?>

/////////////////////////////////////////////
// This is the log if I put all correct data

06-06-05 14:51:39 Debug: beforeValidate()
06-06-05 14:51:39 Debug: Array
(
)

06-06-05 14:51:39 Debug: beforeValidate()
06-06-05 14:51:39 Debug: Array
(
    [User] => Array
        (
            [name] => a
            [surname] => a
            [birth] => 2006-01-01
            [email] => [EMAIL PROTECTED]
            [address] =>
            [city] =>
            [zip] =>
            [state_id] =>
            [dx] =>
            [photo] =>
        )

)

06-06-05 14:51:39 Debug: beforeSave()

//////////////////////////////////////////////////////
// this is the log if I leave empty a mandatory field

06-06-05 15:18:48 Debug: beforeValidate()
06-06-05 15:18:48 Debug: Array
(
)

06-06-05 15:18:48 Debug: beforeValidate()
06-06-05 15:18:48 Debug: Array
(
)


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to