ajax comments form - nothing happens

6 messages Options
Embed this post
Permalink
Kieron

ajax comments form - nothing happens

Reply Threaded More More options
Print post
Permalink
Hi,

In chapter 8, I have followed the code and tried to submit the comment form but nothing happens, it appears that not even the prototype funcs are called let alone the add function in the comments controller.

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 (without the input fields and end):

    echo $ajax->form('/comments/add','post',array('update'=>'comments','url'=>'/comments/add'));

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>

Has anyone had similar problems? Does anyone know what might be wrong?

I'd appreciate any feedback as I've spent a day trying to solve this and have no desire to quit the whole cakephp thing over something like this!

Thanks
Kieron.


Kieron

Re: ajax comments form - nothing happens

Reply Threaded More More options
Print post
Permalink
Sorry this was me being a muppet and missing a basic error in my code!
Caleb

Re: ajax comments form - nothing happens

Reply Threaded More More options
Print post
Permalink
How did you solve it? I have the same problem, have no idea what I did wrong. I even copied the original code, but still doesn't work.
Caleb

Re: ajax comments form - nothing happens

Reply Threaded More More options
Print post
Permalink
Ok, solved it, forget about it. Sorry guys.
Caleb

Re: ajax comments form - nothing happens

Reply Threaded More More options
Print post
Permalink
In case anyone crashes with this again, rename the 'prototype-version.js' in app/webroot/js to 'prototype.js', once downloaded.

This Thread lists the issues regarding Chapter 8:

http://groups.google.com/group/cake-php/browse_thread/thread/7743be2f35ffdd33/39ce0bf2bd025d1c?lnk=raot
davidgolding

Re: ajax comments form - nothing happens

Reply Threaded More More options
Print post
Permalink
In reply to this post by Kieron
I'm confident these errors are due to the newer releases of Cake since the book's publication. I know... a cop-out, but what else can I say? Thanks for your posts here to help readers out, I appreciate it. I'm sure all you have to do to fix the problem is rewrite the $ajax->form() function to match RC3 standards--

$ajax->form(array('controller'=>'comments','action'=>'add'),'post',array('update'=>'comments'));
--Dave

Author, "Beginning CakePHP: From Novice to Professional"

[ get your copy at: http://www.amazon.com/Beginning-CakePHP-Novice-Professional/dp/1430209771/ ]