[eluser]Matt Crowson[/eluser]
In the process of building a simple blog, I was validating a comment post and received this error:
You must use the "set" method to update an entry.
When I remove the validation and just have the comments post straight into the database I have no problem. Anyone have any ideas?
Controller
Code:
class Blog extends Controller {
function Blog()
{
parent::Controller();
$this->load->model('blog_model');
$this->load->library('validation');
$this->load->scaffolding('entries');
$this->load->helper('url');
$this->load->helper('form');
}
function index()
{
$data['heading'] = "Blog";
$data['title'] = "Matthew Crowson";
$data['query'] = $this->db->get('entries');
$this->load->view('blog/blog', $data);
}
function comments()
{
$this->load->library('validation');
$data['heading'] = "Comments";
$data['title'] = "Matthew Crowson";
$this->db->where('entry_id', $this->uri->segment(3));
$data['query'] = $this->db->get('comments');
$this->db->where('id', $this->uri->segment(3));
$data['entry'] = $this->db->get('entries');
$rules['author'] = "required";
$rules['body'] = "required";
$rules['email'] = "required";
$this->validation->set_rules($rules);
$fields['author'] = 'Author';
$fields['body'] = 'Comment';
$fields['email'] = 'Email Address';
$this->validation->set_fields($fields);
if ($this->validation->run() == FALSE)
{
$this->load->view('blog/comments', $data);
}
else
{
redirect('blog/comment_insert');
}
}
function comment_insert()
{
$this->db->insert('comments', $_POST);
redirect('blog/comments/'.$_POST['entry_id']);
}
}
form from the View file
Code:
<?=$this->validation->error_string; ?>
<?=form_open($this->uri->uri_string()); ?>
<?=form_hidden('entry_id', $this->uri->segment(3));?>
<h5>Author</h5>
<input type="text" value="<?=$this->validation->author;?>" name="author" size="50" />
<h5>E-mail</h5>
<input type="text" value="<?=$this->validation->email;?>" name="email" size="50" />
<h5>Comment</h5>
<textarea name="body" value="<?=$this->validation->body;?>" rows="10"></textarea>
<br>
<div><input type="submit" value="Submit" /></div>
</form>