I have a form with various input fields and 3 checkboxes. How can i store these checkbox value in de database in the same field of the database?
This is my code
The form:
<div class="pro-input pro-field">
<label for="name" class="label_title">Name</label>
<?php echo form_input($title); ?>
</div><!--pro-input-->
<div class="pro-text pro-field">
<label for="name" class="label_text">Text</label>
<?php echo form_textarea($text); ?>
</div>
<div class="pro-input pro-field">
<label for="name" class="label_title">URL</label>
<?php echo form_input($url);?>
</div><!--pro-input-->
<div class="pro-checkbox pro-field">
<label for="name" class="label_title">Categorie</label>
<div class="pro-check">
<?php
echo form_label('Code', 'code');
echo form_checkbox('tags[]', 'code');
echo form_label('design', 'design');
echo form_checkbox('tags[]', 'design');
echo form_label('other', 'other');
echo form_checkbox('tags[]', 'other');
?>
</div>
</div>
The Controller:
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('text', 'Text', 'trim|required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('admin/header', $data);
$this->load->view('admin/index', $data);
$this->load->view('admin/footer', $data);
}
else
{
$this->portfolio_model->set_project();
$this->load->view('admin/index', $data);
}
}
The model:
public function set_project()
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text'),
'url' => $this->input->post('url'),
'tags' => $this->input->post('tags')
);
return $this->db->insert('mydb', $data);
}
The value in the database shows '0'. How can i show the 3 values in the same field if they are all checked?
Any help would be highly appreciated. Thank you