How to handle checkboxes - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to handle checkboxes (/showthread.php?tid=354) Pages:
1
2
|
How to handle checkboxes - alexandervj - 11-24-2014 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... Code: public function response_validation(){ Code: <td> RE: How to handle checkboxes - Rufnex - 11-24-2014 Inside your controller you can run a loop for every checked checkbox and attach a logical named file for each value like (untested) PHP Code: foreach($this->input->post('attachments') as $attachement) RE: How to handle checkboxes - alexandervj - 11-24-2014 Thanks for the reply, I'm not sure I understand though. This is the part I'm having trouble with.. // attachments $checked = $this->input->post('attachments'); if ($checked->nui == 1){ //echo 'Nui has been checked'; $this->email->attach('/attachments/somefile.pdf'); } // I dont know how to access the checkboxes correctly RE: How to handle checkboxes - Rufnex - 11-24-2014 PHP Code: foreach($this->input->post('attachments') as $attachement) RE: How to handle checkboxes - alexandervj - 11-24-2014 I see, thanks. It seems to be partially working but now when I receive the email it doesn't include the message part of the email like it did before, it just sends the text "--B_ATC_5473a7876fb89--" and the numbers look like they change everytime an email is sent, and there is no attached file RE: How to handle checkboxes - Rufnex - 11-24-2014 can you post your new code RE: How to handle checkboxes - alexandervj - 11-24-2014 Sure, here is my controller fucntion 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 protected]', "Email"); //$this->email->from($this->input->post('use_email'), "Email"); $this->email->to($this->input->post('send_to')); $this->email->subject($this->input->post('subject')); $message = nl2br($this->input->post('message')); $signature = nl2br($this->input->post('signature')); $message = "<p>".$message."</p>"; $message .= "<p>".$signature."</p>"; $this->email->message($message); // attachments foreach($this->input->post('attachments') as $attachement){ if ($attachement == 'nui'){ $this->email->attach('http://www.site.com/wp-content/uploads/2014/07/image1.jpg'); //this is not the actual location of the files, just made up for privacy } if ($attachement == 'lidar'){ $this->email->attach('http://www.site.com/wp-content/uploads/2014/07/image2.jpg'); } if ($attachement == 'optical'){ $this->email->attach('http://www.site.com/wp-content/uploads/2014/07/image3.jpg'); } // etc. } 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'); } } and heres my view... <td> <input type="checkbox" name="attachments[]" value="nui">NUI-IR Laser Array Chip<br> <input type="checkbox" name="attachments[]" value="lidar">LiDAR - IR Laser Array Field<br> <input type="checkbox" name="attachments[]" value="optical">Optical Solutions<br> <input type="checkbox" name="attachments[]" value="none">None<br> </td> RE: How to handle checkboxes - Rufnex - 11-24-2014 What i see is that your include path for the attachements are wrong. You must use the server path like $this->email->attach('/var/www/..../file.pdf'); RE: How to handle checkboxes - alexandervj - 11-24-2014 I've tried at least 20 different paths and cant seem to get it correct. Not sure if the path would originate where the controller is that runs the code or if it would be somewhere else. I've tried just about everything RE: How to handle checkboxes - Rufnex - 11-24-2014 But you know where the files on the server located? You can echo your current directory Code: echo getcwd(); In your applications, do you send just images like image1, image2 ... ? If so, this would maybe easier PHP Code: <td> |