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!')
        );
*****


I don't have comments_controller and I don't wanna use it. I want to
use comment() function in motives_controller so my form action sends
request to Motive/comment

Validation does work but it doesn't show messages text next to field
in form.
So, if I leave author field in comment blank I'll get error because it
couldn't be saved:
else
{
  $this->Session->setFlash(__('Error!', true));
}

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