If you have no validation for that field in the Model then when you do:
$this->Item->save($this->data);
It will pass the validation:
You should check for invalid fields if you do this in the controller
something like this:
if ($this->Item->invalidFields()) {
if ($this->Item->save($this->data)) {
}
}
And you can add custom text to the field invalidation like this:
$this->Item->invalidate('field_name', 'invalid text or name of invalid
rule if that exists in the model for that field');
On Tue, 2009-05-26 at 02:26 -0700, bram wrote:
> I'm trying to doo some custom validation in a controller.
>
> Code:
>
> if (!empty($this->data))
> {
> "check some things"
>
> if "check failed"
> $this->Item->invalidate('field that failed');
>
> if ($this->Item->save($this->data) {
> }
>
> }
>
> The Item gets saved regardless the check failes or not. While the
> manual clearly says that "save will automatically validate the data
> before actually saving".
>
> There are quite some posts here that address this issue, but I can't
> figure out how to get it working.
>
> In addition to that: Would it be possible to add an error message for
> the invalidation?
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---