After Validation Error Ajax Submission It Does a Regular Submit, Not Ajax.
Hello,
I'm using the Js helper and its submit() method to do an Ajax
submission. Why on the first submission does it do an ajax submission
correctly, but on on a second submission after it re-displays the form
with validation errors it does a full page refresh rather than doing
an ajax submission?
------------------
View:
-------------------
<div id="posts">
<h2>Posts</h2>
<?php foreach($posts as $post): ?>
<p><?php echo $post['Post']['title']; ?></p>
<?php endforeach; ?>
<?php echo $this->Form->create(); ?>
<?php echo $this->Form->input('title'); ?>
<?php echo $this->Js->submit('Submit Post',
array('update'=>'#posts')); ?>
<?php echo $this->Form->end(); ?>
</div>
--------------------------
In my controller:
----------------------------
function index() {
if (!empty($this->data)) {
if ($this->Post->save($this->data)) {
$this->set('posts', $this->Post->find('all'));
$this->render('/elements/posts');
}
else {
$this->render('/elements/form');
}
}
$this->set('posts', $this->Post->find('all'));
}
----------
form element
-----------
<div id="posts">
<?php echo $this->Form->create(); ?>
<?php echo $this->Form->input('title'); ?>
<?php echo $this->Js->submit('Submit Post',
array('update'=>'#posts')); ?>
<?php echo $this->Form->end(); ?>
</div>
I'm just rendering different elements if the save was successful. The
posts element just loops through the posts again and re-displays them.
The form element redisplays the submission form again and it displays
the form errors.
The problem is after it displays the form again with the errors, the
next time I hit submit it does a regular page refresh and completely
ignores that the Js submit button should do an Ajax submission like it
did the first time.
I've also noticed if I hit submit, it will show validation errors, and
if I hit submit again it does a complete refresh, then hit submit one
more time and it does an ajax submission. It seems as if every other
time you hit the submit it will do a complete page refresh rather than
an ajax submission.
Thanks for any help.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home