the fields to be validated must be present in the data that is passed on to
the model
otherwise you would need `require=>true` for those rules that should
trigger even if their fields are not present
I prefer the whitelisting (first approach). but both works.
Am Freitag, 9. März 2012 07:27:30 UTC+1 schrieb alexkd:
>
> Hello all
> I am using CakePHP 1.3.
> In my model validation I added wrong field which is not included in my
> table. Yet the data is saved
> without showing any error.
> Here's my model....
> class patient extends AppModel
> {
> var $name = 'patients';
> var $hasOne = 'Doctors';
> var $validate = array(
> 'login' => array( // The login is not a field in my table
> 'patients'
> 'rule' => array('between', 5, 15),
> 'message' => 'Between 5 to 15 characters'
> )
> );
> }
> Here's my controller....
> <?php
> class PatientsController extends AppController {
> var $helpers = array('Html', 'Form');
> var $name = 'patients';
> var $components = array('Session');
> function index() {
> $this->set('patients', $this->Patient->find('all'));
> }
> function add() {
> if (!empty($this->data)) {
> pr($this->data);
> if ($this->Patient->saveAll($this->data)) {
> $this->Session->setFlash('Your patient has been
> saved.');
> $this->redirect(array('action' => 'index'));
> }
> }
> }
> }
>
> ?>
>
> The problem is the validates function always return true (although it
> contains invalid field)
> What I want is, get an error message when wrong validation is added.
>
> Thanks and Regards
>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php