in your view do a debug($this->data); and you'll probably see the data you posted.
by default a input form will load the data in $this->data as its value - so that if a save fails [i.e. validation fail], you'll keep the data in your view. on successful save, do unset($this->data['Comment']); or set the values you want to clear to be empty [$this->data['Comment']['name'] == '']; On Dec 7, 8:00 pm, Andrei BOGDAN <[email protected]> wrote: > I've change my code and the add action from comments controller looks like > this: > [code] > function add() { > if (!empty($this->data)) { > if ($this->Comment->save($this->data)) { > $this->data = $this->Comment->create(); > $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 { $his->render('add_failure','ajax');} > } > } > [/code] > This function render file add_succes, in with i've put a thank you > messange but the comment form keeps the same value. > The post view looks like this: > [code] > <h1><?=$html->link('<h1>'.$post['Post']['name'].'</h1>','/posts/view/'.$post['Post']['id'],null,null,false);?></h1> > <p>Author: <?=$post['User']['firstname'];?> > <?=$post['User']['lastname'];?></p> > <p>Date Published: <?=$time->nice($post['Post']['date'], null);?></p> > <hr /> > <p><?=$post['Post']['content'];?></p> > <hr /> > <h2>:: Comments ::</h2> > <? foreach($comments as $comment): ?> > <div id="comments" class="comment"> > <p><strong><?=$comment['Comment']['name'];?></strong></p> > <p><?=$comment['Comment']['content'];?></p> > <div id="vote_<?=$comment['Comment']['id'];?>"> > <div class="cast_vote"> > <ul> > > <li><?=$ajax->link('up','/comments/vote/up/'.$comment['Comment']['id'],array('update'=>'vote_'.$comment['Comment']['id']),null,false);?></li> > > <li><?=$ajax->link('down','/comments/vote/down/'.$comment['Comment']['id'],array('update'=>'vote_'.$comment['Comment']['id']),null,false);?></li> > </ul> > </div> > <div class="vote"><?=$comment['Comment']['votes'];?></div> > </div> > </div> > <? endforeach; ?> > <!-- Create ajax form ver 2 asta buna --> > <div style="float: left;clear: both;"> > <?=$form->create('Comment',array('action'=>'add','onSubmit'=>'return > false;'));?> > <?=$form->input('Comment.name');?> > <?=$form->input('Comment.content');?> > <?=$form->input('Comment.post_id', > array('type'=>'hidden','value'=>$post['Post']['id']));?> > <?=$ajax->submit('Add Comment', > array('url'=>'/comments/add','update'=>'comments'));?> > </form> > </div> > [/code] > > - > Andrei Bogdan > > 2009/12/7 John Andersen <[email protected]>: > > > > > Change your code to: > > > [code] > > if (!empty($this->data)) { > > if ($this->Comment->save($this->data)) { > > $this->data = $this->Comment->create(); > > $comments = $this->Comment->find('all', array('conditions' => > > array('post_id' => $this->data['Comment']['post_id']), 'recursive' => > > -1)); > > [/code] > > > Your save statement will automatically perform a Create, so no need to > > do it yourself before the save. > > > Using the create statement inside the if statement, sets the > > controllers data to an empty Comment structure, thus giving your form > > an empty content. > > > Enjoy, > > John > > > On Dec 7, 9:27 am, Andrei BOGDAN <[email protected]> wrote: > >> the code in the add action looks like 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 { $his->render('add_failure','ajax');} > >> } > >> } > > >> - > >> Andrei Bogdan > > >> 2009/12/7 #2Will <[email protected]>: > > >> > What's the code in the action when submitted? > > >> > The values will remain until you o something and then redirect. > >> > eg. save the comment, dd a message to the flash message thing and > >> > then redirect to the page. > > >> > it's the redirect bit that clears the form. > > >> > On Dec 7, 7:38 am, "andrei.b" <[email protected]> wrote: > >> >> hello, > >> >> I have a comment view for a blog witch looks like this: > > >> >> <div class="comments form"> > >> >> <?php echo $form->create('Comment');?> > >> >> <fieldset> > >> >> <legend><?php __('Add Comment');?></legend> > >> >> <?php > >> >> echo $form->input('name', array('value' => '')); > >> >> echo $form->input('content', array('value' => '')); > >> >> echo $form->input('post_id'); > >> >> ?> > >> >> </fieldset> > >> >> <?php echo $form->end('Submit');?> > >> >> </div> > > >> >> When I press submit in name and content input fields I still see the > >> >> same values that I entered instead of viewing nothing. > > >> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others > >> > with their CakePHP related questions. > > >> > 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 > >> > athttp://groups.google.com/group/cake-php?hl=en > > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others > > with their CakePHP related questions. > > > 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 > > athttp://groups.google.com/group/cake-php?hl=en- Hide quoted text - > > - Show quoted text - Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
