Need assist Filtering Comments/Returning Errors to appropriate view. |
[eluser]dancrew32[/eluser]
Hey CodeIgniters, I'm a little new and trying to add some filtering to the inputs of content along the lines of this CMS tutorial, but I am having some difficulty: - Inserting filtered (xss_filter / prep_for_form) content to the database - Returning the errors (associated with the defined $rules) in the appropriate "Comment View" ($this->validation->error_string - Obtaining the correct "Comment View" after performing an erroneous insert_comment() method. Here is my code: ---- Controller: http://pastie.org/483538 Model: http://pastie.org/483540 View: http://pastie.org/483542 Comment View: http://pastie.org/483543 Any assists to point me in the right direction would be highly appreciated. Thank you for your time.
[eluser]Thorpe Obazee[/eluser]
First of all, try using the new Form_Validation Library. The Validation Library you are using has been deprecated.
[eluser]dancrew32[/eluser]
[quote author="bargainph" date="1242807007"]First of all, try using the new Form_Validation Library. The Validation Library you are using has been deprecated.[/quote] I loaded that new Form_Validation library and updated the validation in the view and controller. here is the new movie_comment_view.php and Movie.php Still not sure how to get back to the add/display comments view after passing invalid data: Code: if ($this->form_validation->run() == FALSE) { Here are the errors that I'm getting after entering just a ['comment'] and leaving ['author'] blank (in an attempt to input invalid data: Errors.png
[eluser]Thorpe Obazee[/eluser]
Code: if ($this->form_validation->run() === TRUE) {
[eluser]dancrew32[/eluser]
[quote author="bargainph" date="1242809196"] Code: if ($this->form_validation->run() === TRUE) { That works fine when passing in valid data, but when passing invalid data, it just goes to a blank page with this header: (index.php/movie/insert_comment) I need a way to get back to index.php/movie/comments/X after passing invalid data (X being the original comment page I was on). Here are the errors that I was getting in the previous post after entering just a [‘comment’] and leaving [‘author’] blank (in an attempt to input invalid data: Errors.png (Thanks for helping btw, you rock.)
[eluser]Thorpe Obazee[/eluser]
Hmm... I think I get it now. where do you point your 'form_open()'? I mean to which method does it submit? I'd submit it to the comments method then do the 'add' logic there.
[eluser]dancrew32[/eluser]
form_open() points to movie/insert_comment in movie_comment_view.php: Code: <p><?php echo $this->form_validation->error_string; ?></p> I thought there was a way to keep all of the functions for inserting, updating, deleting entries in separate functions.. I think if I nest all of them inside of comment(), it will get kinda messy.. does that make sense? There must be a way to keep them all separate and tidy =/
[eluser]Thorpe Obazee[/eluser]
You can still do that but I wouldn't submit to movie/insert_comment. Submit to movie/comments then call the method, insert_comment from there via: Code: $success = $this->insert_comment(); edit: it's probably better to set insert_comment to private if you do this option.
[eluser]dancrew32[/eluser]
I threw in some pseudocode in comments() because I'm not particularly sure how to do form_open('movie/comments'); and trigger some kind of conditional statement to run through insert_comment($data). Code: function comments() Sorry for noobin ya..
[eluser]Thorpe Obazee[/eluser]
[quote author="dancrew32" date="1242812094"]I threw in some pseudocode in comments() because I'm not particularly sure how to do form_open('movie/comments'); and trigger some kind of conditional statement to run through insert_comment($data). Code: function comments() Sorry for noobin ya..[/quote] Code: // in your view untested but please try this. |
Welcome Guest, Not a member yet? Register Sign In |