Hi,
I am trying to add a comments form to a blog post, updating the page
with ajax, specifically using prototype.js.
I've used ajax->form, however when I press the submit button
absolutely nothing happens.
I've tried the ajax submit method with the same result. If I submit
the form without ajax it works fine.
my view code is as follows:
echo $ajax->form('/comments/
add','post',array('update'=>'comments','url'=>'/comments/add'));
echo $form->input('Comment.name');
echo $form->input('Comment.content');
echo $form-
>input('Comment.post_id',array('type'=>'hidden','value'=>$post['Post']
['id']));
echo $form->end('Add Comment');
the add action in the comments controller is as follows:
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_success','ajax');
} else {
$this->render('add_failure', 'ajax');
}
}
}
and the created source is as follows:
<div id="comments">
<form id="form283226270" onsubmit="event.returnValue = false;
return false;" method="post" action="/blog/comments/add">
<fieldset style="display:none;">
<input type="hidden" name="_method" value="POST" />
</fieldset>
<script type="text/javascript">
//<![CDATA[
Event.observe('form283226270', 'submit', function(event) { new
Ajax.Updater('comments','/blog/comments/add', {asynchronous:true,
evalScripts:true, parameters:Form.serialize('form283226270'),
requestHeaders:['X-Update', 'comments']}) }, false);
//]]>
</script>
<div class="input text">
<label for="CommentName">Name</label>
<input name="data[Comment][name]" type="text" maxlength="100"
value="" id="CommentName" />
</div>
<div class="input textarea">
<label for="CommentContent">Content</label>
<textarea name="data[Comment][content]" cols="30" rows="6"
id="CommentContent" ></textarea>
</div>
<input type="hidden" name="data[Comment][post_id]" value="7"
id="CommentPostId"/>
<div class="submit">
<input type="submit" value="Add Comment" />
</div>
</form>
</div>
Does anyone know what might be wrong?
I'd appreciate any feedback as I've spent a whole day trying to solve
this and have no desire to quit the whole cakephp thing over something
like this!
Thanks
Kieron.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---