I have a view were I show a news and it's related comments.
There is also a form in the view where the user can enter a new
comment.

I want to save the new comment in the news controller comment action,
because I don't want to use a comments controller.

Everything works well except the fact that the validation error
messages are not shown, but the validation works as expected. So when
I fill both fields the data is saved. If one or both fields are left
blank, the data is not saved and the form is shown agaib. But there
are no error messages.

I asked google and tried several things over the whole day, but
nothing helped. So any help is highly appreciated. :-)


That is the code I use to generate the form:

<?php
                echo $form->create(
                    null,
                    array(
                        'url' => array(
                                'controller' => 'news',
                            'action' => 'comment'
                        )
                    )
                );
                echo $form->input(
                    'Comment.foreign_id',
                    array(
                        'type' => 'hidden',
                        'value' => $the_news['News']['id']
                    )
                );
                echo $form->input(
                    'Comment.nickname',
                    array(
                        'label' => 'Nickname:',
                        'error' => 'This field cannot be left blank.'
                    )
                );
                echo $form->input(
                    'Comment.text',
                    array(
                        'label' => 'Text:',
                        'error' => 'This field cannot be left blank.'
                    )
                );
                echo $form->end('Abschicken');
            ?>


This is the code of my comment action:

function comment() {
                if(!empty($this->data)) {
                        if ($this->News->Comment->save($this->data)) {
                // Message for the user
                $this->flash(
                        'The comment was saved..',
                        array(
                                'controller' => 'news',
                                'action' => 'view',
                                $this->data['Comment']['foreign_id']
                        ),
                        2
                );
            } else {
                // Get the news to show the title when a validation error
occurs
                $the_news = $this->News->find(
                    'first',
                    array(
                        'conditions' => array(
                            'News.id' => $this->data['Comment']
['foreign_id']
                        ),
                        'recursive' => 1
                    )
                );

                $this->set('the_news', $the_news);
            }
                }
        }


--~--~---------~--~----~------------~-------~--~----~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to