I have a model not derived from a table, with one validation rule.
class Tablelessmodel extends AppModel
{
var $useTable = false;
var $_schema = array(
'firstname' =>array('type'=>'string',
'length'=>20),
'lastname' =>array('type'=>'string',
'length'=>20),
'testfield' =>array('type'=>'number',
'length'=>5));
var $validate = array(
'testfield' => array('rule'=>'numeric','message'=>'Numbers
only.'));
}
It is listed in the $uses array of another controller, it does not
have its own controller. When I get POST data, I do the following in
this other controller:
$tablelessmodel = new Tablelessmodel;
if($tablelessmodel->save($this->data)) $this->Session->setFlash(__
('Validated.', true));
else $this->Session->setFlash(__('Not Validated.', true));
And in the view, this is an example of a field in the form:
<?php echo $form->input('Tablelessmodel.testfield',array
('label'=>'Test Field','size'=>'5')); ?>
There are other fields in the form that are defined like this:
<?php echo $form->input('otherfield',array('label'=>'Other
Field','size'=>'5')); ?>
When $this->data comes into the controller, the form fields are
separated into the proper arrays of ['Tablelessmodel'] and
['ModelForCurrentController'].
Everything works fine, the flash shows if it validated or not, and the
error report contains the name of the invalid field with the message
attached to the validation rule, and the form on reload contains all
of the previously inputted data waiting for corrections before being
submitted again. But I can't figure out why the validation message
that should be generated by the form element code does not come up.
Any help would be greatly appreciated!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---