Adding comments to a post - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Adding comments to a post (/showthread.php?tid=59619) |
Adding comments to a post - El Forum - 10-28-2013 [eluser]Lykos22[/eluser] Hi all, I'd like some help please, I 've completly stuck! I have a post page that has the full post and below the post a small form for adding comments. The uri of the post page is: site/posts/1, so it is in posts controller, and the form action is form_open(site_url('comments/add/'.$post->post_id)). This is my add() function inside comments controller: Code: public function add($post_id){ and this is the add() function inside the comment model: Code: public function add($post_id){ What I'm trying to do is if the $result = $this->comment_model->add($post_id); fails the validation to display the validation errors in my post view, else insert the comment and redirect to the same post page (site/posts/1). The problem is that when I hit submit the form action goes in the comments/add/1, as expected, but doesn't do any these above. Any ideas how can I fix this?? Can also found here Adding comments to a post - El Forum - 10-29-2013 [eluser]rappasoft[/eluser] You seem to be returning an id on success but not checking if it was false or not: This: Code: if ($this->form_validation->run() == true) { Could be this: Code: if ($this->form_validation->run() == true) { Adding comments to a post - El Forum - 10-29-2013 [eluser]Lykos22[/eluser] The problem was that I wasn't passing the validation_errors() back to the Posts controller, due to the redirect all the validation errors were lost. So the only solution I found was to store them in flashdata and send them back to the Posts controller. However if there's another better way I'd be grateful if you could inform me. |