Welcome Guest, Not a member yet? Register   Sign In
Need assist Filtering Comments/Returning Errors to appropriate view.
#13

[eluser]dancrew32[/eluser]
Code:
function comments()
{
    $data['title']    = 'Comments List';
    $data['comments'] = $this->Movie_model->fetchRow($this->uri->segment(3), 'movie_id', 'movie_comments');
    
        $this->_insert_comment();
    
    $this->load->view('front/movie_comment_view', $data);
}

private function _insert_comment()
{
    $this->form_validation->set_rules('comment', 'Comment', 'required|min_length[1]|max_length[100]|xss_clean|prep_for_form');
    $this->form_validation->set_rules('author', 'Author', 'required|min_length[1]|max_length[40]|xss_clean|prep_for_form');
    
    if ($this->form_validation->run() === TRUE) {
        $data['comment']  = $this->input->post('comment', TRUE);
        $data['author']   = $this->input->post('author', TRUE);
        $data['movie_id'] = $this->input->post('movie_id', TRUE);
        
        $this->Movie_model->insertRow('movie_comments', $data);
        redirect(current_url().'/'.$data['movie_id']);
    } else {
// I did this section to prevent the redirect loop if no data was entered (the movie_id, luckily, always posts, so I can test with it)
        $data['movie_id'] = $this->input->post('movie_id', TRUE);
        if ($data['movie_id'] != NULL) {
            redirect(current_url().'/'.$data['movie_id']);
        }
    }
}

Whew. This works. It's not terribly good looking, but seems to work for all conditions, filters xss, doesn't do htmlspecialchars yet (I'm not sure prep_for_form is what I should be using..) I just have to get it to report errors back to this:
Code:
<p>&lt;?php echo $this->form_validation->error_string; ?&gt;</p>

Thank you for the major help! You rule.


Messages In This Thread
Need assist Filtering Comments/Returning Errors to appropriate view. - by El Forum - 05-19-2009, 11:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB