[eluser]Skoobi[/eluser]
Hi I'm trying to add checkbox values to the database from a form but can seem to get them all in to the same field.
What i want to do is have 5 or more different checkboxes so 'item1', 'item2', 'item3' and so on then if item1 and 3 are selected it will post them to the 'Items' field in the database as they are described in the values so in this example i want it to display in the database like this 'item1, item3' ...
Is this possible or do i need to explode the array before sending it to the database??
Heres my code so far :
View:
Code:
<div class="panel-body">
<div class="checkbox">
<p><label><input type="checkbox" name="features[]" value="about"> About</label></p>
<p><label><input type="checkbox" name="features[]" value="contact"> Contact</label></p>
<p><label><input type="checkbox" name="features[]" value="services"> Services</label></p>
<p><label><input type="checkbox" name="features[]" value="catalog"> Interactive catalogue</label></p>
<p><label><input type="checkbox" name="features[]" value="newsletter"> Newsletter</label></p>
<p><label><input type="checkbox" name="features[]" value="youtube"> YouTube</label></p>
<p><label><input type="checkbox" name="features[]" value="facebook"> Facebook</label></p>
<p><label><input type="checkbox" name="features[]" value="twitter"> Twitter</label></p>
<p><label><input type="checkbox" name="features[]" value="blog"> Blog</label></p>
<p><label><input type="checkbox" name="features[]" value="directions"> Directions</label></p>
<p><label><input type="checkbox" name="features[]" value="images"> Images / Gallery</label></p>
</div>
</div>
Controller:
Code:
public function newApp()
{
$this->is_logged_in();
$this->form_validation->set_rules('customerid', 'Customerid', 'trim|xss_clean|numeric');
$this->form_validation->set_rules('title', 'Application Title', 'trim|required|max_length[12]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
$this->form_validation->set_rules('webaddress', 'Web Address', 'trim|required');
$this->form_validation->set_rules('businessname', 'Business Name', 'trim|required|max_length[20]');
$this->form_validation->set_rules('telephone', 'Telephone Number', 'trim|required|max_length[14]|numeric');
$this->form_validation->set_rules('order_status', 'Order Status', 'numeric');
$this->form_validation->set_rules('published', 'Published', 'numeric');
$this->form_validation->set_error_delimiters(' <span class="text text-danger"><small>','</small></span>');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/includes/header');
$this->load->view('admin/apps/new');
$this->load->view('admin/includes/footer');
}
else
{
$this->admin_model->create_app();
$this->session->set_flashdata('message', '<div class="alert alert-success"><p>Application created!!!</p></div>');
redirect('admin/apps', 'refresh');
}
}
Model:
Code:
public function create_app()
{
$data = array(
'customerid' => $this->input->post('customerid'),
'title' => $this->input->post('title'),
'email' => $this->input->post('email'),
'webaddress' => $this->input->post('webaddress'),
'businessname' => $this->input->post('businessname'),
'telephone' => $this->input->post('telephone'),
'features' => $this->input->post('features[]'),
'order_status' => $this->input->post('order_status'),
'published' => $this->input->post('published'),
);
$this->db->insert('apps',$data);
}
Cheers
Chris