Re: Validating data always fails, why?
if you want to do the validation manually, in CakePHP 1.2 use the following: if ($this->User->create($this->data) && $this->User->validates()) { // validation ok } else { // validation failed } otherwise, use $this->User->save($this->data) directly as Grant Cox pointed out. On Jul 7, 4:18 am, Steveston <[EMAIL PROTECTED]> wrote: > in model: > var $validate = array > ( > //'username' => '/[0-9]{8}$/', > //'student_no'=> '/[0-9]{8,9}$/', > 'last_name' => '/[a-zA-Z]$/', > 'first_name'=> '/[a-zA-Z]$/', > //'password'=>'/^.{5,8}/', > 'email'=>VALID_EMAIL > ); > > in controller: > > if ($this->User->validate($this->data)) > { > $this->User->save($this->data); > echo "Saved"; > } > else > { > $this->validateErrors($this->User); > echo 'Not saved'; > } > > Submitted form: > first name: Test > last name: test > email: [EMAIL PROTECTED] > student #:12345678 > > This data is supposed to pass data validation, but it turns out it > always fails, as I always get "Not saved" printout. > > Even weird, if I purposely add some number after some letters as first > name or last name, I do not get error message (I have set $html- > > >tagError correctly in view page). All I get is still "Not saved". > > Any idea? Where did make mistake? > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Validating data always fails, why?
Your controller should be much simpler - like: if ( $this->User->save($this->data) ){ echo "saved"; } else { $this->log( $this->User->validationErrors ); echo "not saved"; } the save() call automatically validates the data, and will not save if it does not pass validation. The log() call will write out the validation errors to your app/tmp/logs/error.log file, and it should identify which values are not passing. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Validating data always fails, why?
in model: var $validate = array ( //'username' => '/[0-9]{8}$/', //'student_no'=> '/[0-9]{8,9}$/', 'last_name' => '/[a-zA-Z]$/', 'first_name'=> '/[a-zA-Z]$/', //'password'=>'/^.{5,8}/', 'email'=>VALID_EMAIL ); in controller: if ($this->User->validate($this->data)) { $this->User->save($this->data); echo "Saved"; } else { $this->validateErrors($this->User); echo 'Not saved'; } Submitted form: first name: Test last name: test email: [EMAIL PROTECTED] student #:12345678 This data is supposed to pass data validation, but it turns out it always fails, as I always get "Not saved" printout. Even weird, if I purposely add some number after some letters as first name or last name, I do not get error message (I have set $html- >tagError correctly in view page). All I get is still "Not saved". Any idea? Where did make mistake? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---