Hello people,

Im just starting with CakePHP, and so far it's great. But now im
making a tutorial for a blog. And i want to add comments using Ajax.

I've installed prototype, and that's working. But i have a form in my
posts/view.ctp file. And i want to use the comments controller for
adding a post to the database.

so i've used this:

<?=$ajax->form('/comments/add', 'post', array('update'=>'comments')); ?
>
<?= $form->input('naam'); ?>
<?= $form->input('content'); ?>
<?= $form->input('comment.post_id',array('type'=>'hidden','value'=>
$post['Post']['id']));?>
<?= $form->end('Comment toevoegen'); ?>

The action in the comments controller is this:
function add()
        {
                if(!empty($this->data))
                {
                        $this->Comment->create();
                                if ($this->Comment->save($this->data))
                                {
                                        $comments = 
$this->Comment->find('all',array('conditions'=>array
('post_id'=>$this->data['Comment']['post_id']), 'recursive'=> -1));
                                        $this->set(compact('comments'));
                                        $this->render('add_succes','ajax');
                                }
                                else
                                {
                                        $this->render('add_failure','ajax');
                                }
                        }
                }

But somehow the source of the form is this:

<form id="form1521548612" onsubmit="event.returnValue = false; return
false;" method="post" action="/posts/comments/add"><fieldset
style="display:none;"><input type="hidden" name="_method"
value="POST" /></fieldset><script type="text/javascript">
//<![CDATA[
Event.observe('form1521548612', 'submit', function(event) { new
Ajax.Updater('comments','/posts/comments/add', {asynchronous:true,
evalScripts:true, parameters:Form.serialize('form1521548612'),
requestHeaders:['X-Update', 'comments']}) }, false);
//]]>
</script>       <div class="input text"><label for="naam">Naam</label><input
name="data[naam]" type="text" value="" id="naam" /></div>       <div
class="input text"><label for="content">Content</label><input
name="data[content]" type="text" value="" id="content" /></div> <input
type="hidden" name="data[comment][post_id]" value="19"
id="commentPostId" />   <div class="submit"><input type="submit"
value="Comment toevoegen" /></div></form>

so when i try to add a comment i get a error that there is not an
action in my posts controller called "comments"
Why does he add "posts" in the action of the form. I know that im in
the posts controller, but i thought if you start with "/" in starts in
the root of your controller files?

Who can help me?

Thanks

 Chris

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to