11-24-2014, 02:02 PM
I have a form that collects a user input to be emailed, including a few checkboxes which I want to attach different .pdfs if they are checked. But I'm not sure how to set up my if statement regarding the checkboxes. I havent worked with them before in codeigniter. Here is my controller function...
and here is how I have my checkboxes in my view. The form submits fine, the problem is I just dont know how to access the checkbox array in the controller...
Code:
public function response_validation(){
$this->load->library('form_validation');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
$this->form_validation->set_rules('attachments', 'Attachments', 'required');
$this->form_validation->set_rules('use_email', 'Email', 'required');
if($this->form_validation->run()){
//load email library and model_users
$this->load->library('email', array('mailtype'=>'html'));
$this->load->model('model_users');
//build email message
$this->email->from('email@email.com', "email");
//$this->email->from($this->input->post('use_email'), "From Me");
$this->email->to($this->input->post('send_to'));
$this->email->subject($this->input->post('subject'));
$message = "<p>".$this->input->post('message')."</p>";
$message .= "<p>".$this->input->post('signature')."</p>";
$this->email->message($message);
// attachments
$checked = $this->input->post('attachments');
if ($checked->nui == 1){
//echo 'Nui has been checked';
$this->email->attach('/attachments/somefile.pdf');
}
//
$this->email->send();
//send email
if ($this->email->send()){
$this->load->view('response_sent');
} else {
echo "There was a problem. Please contact the Administrator.";
}
} else {
$this->load->view('main/request_details/$r->Submitted');
}
}
Code:
<td>
<input type="checkbox" name="attachments[]" value="nui">NUI-IR<br>
<input type="checkbox" name="attachments[]" value="lidar">LiDAR<br>
<input type="checkbox" name="attachments[]" value="optical">Optical<br>
<input type="checkbox" name="attachments[]" value="none">None<br>
</td>