i am trying to do a simple form that adds a new comment using ajax to a blog post (actually this is a part of a cakePHP tutorial)
but the problem is that the submit button do nothing at all
here is the part of code that generates the form in the view.ctp file
<?php echo $ajax->form('/comments/add', 'post', array('url' => '/comments/add', 'update' => 'PostsComments', 'indicator' => 'commentSaved'));?>
<fieldset>
<legend><?php __('Add Comment');?></legend>
<?php
echo $form->hidden('Comment.post_id', array('value' => $post['Post']['id']));
echo $form->input('Comment.name');
echo $form->input('Comment.content');
?>
</fieldset>
<?php echo $form->end('Submit');?>
and here is the add comment action in the comments_controller.php
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_success','ajax');
} else {
$this->render('add_failure','ajax');
}
}
the problem is that the action add isnt called from the view ... when i viewed the generated html source code i found something like that
<form id="form304217296" onsubmit="event.returnValue = false; return false;" method="post" action="/php-cake/blog/comments/add"><fieldset style="display:none;">
if i removed the on submit tag manually then the action is called but the add_success.ctp is generated as a new page not as an ajax call.
so what could be the problem ?