[eluser]swgj19[/eluser]
Codeigniter version: 2.1.2
I am working on a blog site that has an admin panel. In the admin panel a user can create a category for the blog with a status of active or inactive. When the category is active, the category shows on the home page. When the category status is inactive, the category is saved to the database, but inactive to the public.
For some reason, when creating a category in the admin panel under categories, when status is chosen as "active" or "inactive", the status is not updating when data from form is sent to database.
Below are partials of the mvc.
View: admin_cat_create
Code:
<h1><?php echo $title;?></h1>
<?php
echo form_open('admin/categories/create');
echo "<p><label for='catname'>Name</label><br/>";
$data = array('name'=>'name','id'=>'catname','size'=>25);
echo form_input($data) ."</p>";
echo "<p><label for='short'>Short Description</label><br/>";
$data = array('name'=>'short_desc','id'=>'short','size'=>40);
echo form_input($data) ."</p>";
echo "<p><label for='long'>Long Description</label><br/>";
$data = array('name'=>'long_desc','id'=>'long','rows'=>5, 'cols'=>'40');
echo form_textarea($data) ."</p>";
echo "<p><label for='status'>Status</label><br/>";
$options = array('active' => 'active', 'inactive' => 'inactive');
echo form_dropdown('status',$options) ."</p>";
echo "<p><label for='order'>Sort Order</label><br/>";
$data = array('name'=>'sort_order','id'=>'order','size'=>5);
echo form_input($data) ."</p>";
echo form_submit('submit','create category');
echo form_close();
Controller: categories
Code:
function create(){
if ($this->input->post('name')){
$this->MCats->addCategory();
$this->session->set_flashdata('message','Category created');
redirect('admin/categories/index','refresh');
}else{
$data['title'] = "Create Category";
$data['main'] = 'admin_cat_create';
$data['categories'] = $this->MCats->getTopCategories();
$this->load->vars($data);
$this->load->view('dashboard');
}
}
Model: mcats
Code:
function addCategory(){
$data = array(
'name' => str_replace(" ", "_",$this->input->post('name')),
'short_desc' => $this->input->post('short_desc'),
'long_desc' => $this->input->post('long_desc'),
//status in form holds array
//'status' => $this->input->post('status',$options),
'status' => $this->input->post('status'),
'sort_order' => $this->input->post('sort_order')
);
$this->db->insert('categories', $data);
}
so looking at the above code, $options is passed with the 'status' name in the view. And in the database I have a table called categories with a column named 'status' with the type set as enum 'active' and 'inactive'. 'active' is default.
So far, the form when submitted is not updating the database.
I think the problem has to do with passing $options.
Any pointers on where the problem lies? Thanks for your input.