[eluser]faxtion[/eluser]
View
Code:
<?php echo validation_errors(); ?>
<?php
$attributes = array('class' => 'email', 'id' => 'myform');
echo form_open('admin/add/', $attributes);
?>
<h5>Title</h5>
<input type="text" name="title" value="" size="50" />
<h5>Body</h5>
<textarea name="body">
</textarea>
<h5>Excerpt</h5>
<textarea rows="2" cols="38" name="excerpt">
</textarea>
<h5>Image</h5>
<input type="text" name="image" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
Controller
Code:
function add() {
$this->load->helper(array('file','form','url'));
$this->load->library('form_validation');
$this->load->model('Modeladmin', '', TRUE);
$this->form_validation->set_rules('title', 'Title', 'required');
if ($this->form_validation->run() == TRUE) {
$article_data = $this->Modeladmin->add_article();
redirect('/admin/','refesh');
} else {
$this->load->view('admin/add');
}
}
Model
Code:
function add_article() {
$article_data = array(
//'id' => $this->input->post('id'),
'title' => $this->input->post('title'),
'body' => $this->input->post('body'),
'excerpt' => $this->input->post('excerpt'),
);
$this->db->insert('articles', $article_data);
}