Question

i am trying to generate a multiple chechkbox in codeigniter which will allow to send emails to the email selected from the checkbox.

The form_multiselect didnt help me ...

Thanks..

Was it helpful?

Solution

Here's some example code... don't use in production, there's only explanation how to proceed data / validation / view

CONTROLLLER

    function test() 
  {
 $this->load->helper(array('form', 'url'));
 $this->load->library('form_validation');

 $this->form_validation->set_rules('emailRecipient[]', 'User Mail', 'required');

  if ($this->form_validation->run() == FALSE)
        {
      $data['PreEmailRecipient'] = array(
                'mail 1' => 'mail1@gmail.com',
                'mail 2' => 'mail2@gmail.com',
                'mail 3' => 'mail3@gmail.com',
                'mail 4' => 'mail4@gmail.com',
                'mail 5' => 'mail5@gmail.com',
                'mail 6' => 'mail6@gmail.com',
                'mail 7' => 'mail7@gmail.com',
                'mail 8' => 'mail8@gmail.com',
                'mail 9' => 'mail9@gmail.com'
                );
            $this->load->view('test',$data);
        }
        else
        {
      foreach ($this->input->post('emailRecipient') as $key => $value)
      {
        echo $value.'<br />';
        //your code....   
      }      
        }
    }

VIEW

<?php echo validation_errors(); ?>
   <?php echo form_open('welcome/test');?>
      <?php foreach($PreEmailRecipient as $key => $value) : ?>
        <input type="checkbox" name="emailRecipient[]" value="<?php echo $value;?>">&nbsp;<?php echo $key;?><br />
      <?php endforeach;?>  
        <input type="submit" value="Submit" />
    </form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top