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

[eluser]dancrew32[/eluser]
updated, entered blah in 'comments' and blah in 'author' outputs this.png
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data <-- thinking that's the problem

Filename: controllers/Movie.php

Line Number: 41 <-- this should be fine
A Database Error Occurred

You must use the "set" method to update an entry.

(with the &lt;?php echo form_open('movie/comments'); ?&gt; added)

I need to assign something to $data still huh?
#12

[eluser]Thorpe Obazee[/eluser]
Code:
private function _insert_comment()
{
    $this->form_validation->set_rules('comment', 'Comment', 'required|min_length[1]|max_length[100]|xss_clean|prep_form');
    $this->form_validation->set_rules('author', 'Author', 'required|min_length[1]|max_length[40]|xss_clean|prep_form');
            
    if ($this->form_validation->run() === TRUE) {
        $_POST = xss_clean($_POST);
        $this->Movie_model->insertRow('movie_comments', $_POST);
        redirect(current_url());    
    }
}

or

Code:
private function _insert_comment()
{
    $this->form_validation->set_rules('comment', 'Comment', 'required|min_length[1]|max_length[100]|xss_clean|prep_form');
    $this->form_validation->set_rules('author', 'Author', 'required|min_length[1]|max_length[40]|xss_clean|prep_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());    
    }
}

The error occurred because there wasn't any $data variable set.
#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.
#14

[eluser]Thorpe Obazee[/eluser]
No problem. Btw, I'd use validation_errors() in the view instead of $this->form_validation->error_string.




Theme © iAndrew 2016 - Forum software by © MyBB