Hello everyone,

I have two models

MOTIVE  var $hasMany = array('Comment');
COMMENT var $belongsTp=array('Motive');

I want to make comments on motives so I added comment() function into
Motive controller and in views/motive/view.php I added following form:
****
        echo $form->create('Motive',array('action' => 'comment'));
        echo $form->hidden('Comment.motive_id',array('value'=>
$motive['Motive']['id']));
        echo $form->input('Comment.author');
        echo $form->input('Comment.text',array('type'=>'textarea'));
        echo $form->end('Send');
****

In comment() function of Motives controller i have:
****
if (!empty($this->data)) {
        if($this->Motive->Comment->save($this->data))
        {
                $this->Session->setFlash(__('Posted!', true));
               $this-
>redirect(array('controller'=>'motives','action'=>'view/'.$this-
>data['Comment']['motive_id'].''));
        }
        else
        {
                $this->Session->setFlash(__('Error!', true));

        }
}
****

I also added validation to my comment model:
*****
        var $validate = array(
                        'author' => 
array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank
field!'),
                        'text' => 
array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank field!')
        );
*****

and there seems to be a problem. If I leave an empty author field it
will not throw a validation error?

I think this has something to do with putting comment() function in
motives_controller and than expecting comment model validation to do
the job?!?!

How can I make my validation work so it redirects back to the form and
throws an error next to the field that was left empty etc.?

thnx
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to