How to handle checkboxes |
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>
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)
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
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
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>
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
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> |
Welcome Guest, Not a member yet? Register Sign In |