在codeigniter中生成一个多重复选框?

时间:2013-01-31 08:00:35

标签: php codeigniter multipleselection

我正在尝试在codeigniter中生成一个多个chechkbox,它允许将电子邮件发送到从复选框中选择的电子邮件。

form_multiselect对我没有帮助......

谢谢..

1 个答案:

答案 0 :(得分:2)

以下是一些示例代码...不在生产中使用,只有如何进行数据/验证/查看的解释

<强> 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....   
      }      
        }
    }

查看

<?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>