• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle checkboxes

#1
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(){
    
    $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');
    }
    
   }
 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:
<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>
Reply


Messages In This Thread
How to handle checkboxes - by alexandervj - 11-24-2014, 02:02 PM
RE: How to handle checkboxes - by Rufnex - 11-24-2014, 02:23 PM
RE: How to handle checkboxes - by alexandervj - 11-24-2014, 02:31 PM
RE: How to handle checkboxes - by Rufnex - 11-24-2014, 02:36 PM
RE: How to handle checkboxes - by alexandervj - 11-24-2014, 02:50 PM
RE: How to handle checkboxes - by Rufnex - 11-24-2014, 02:52 PM
RE: How to handle checkboxes - by alexandervj - 11-24-2014, 02:57 PM
RE: How to handle checkboxes - by Rufnex - 11-24-2014, 03:07 PM
RE: How to handle checkboxes - by alexandervj - 11-24-2014, 03:48 PM
RE: How to handle checkboxes - by Rufnex - 11-24-2014, 03:52 PM
RE: How to handle checkboxes - by alexandervj - 11-24-2014, 03:55 PM
RE: How to handle checkboxes - by InsiteFX - 11-24-2014, 11:11 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.