Adding comments to a post |
[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
[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) {
[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. |
Welcome Guest, Not a member yet? Register Sign In |