我正在尝试在codeigniter中生成一个多个chechkbox,它允许将电子邮件发送到从复选框中选择的电子邮件。
form_multiselect对我没有帮助......
谢谢..
答案 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;?>"> <?php echo $key;?><br />
<?php endforeach;?>
<input type="submit" value="Submit" />
</form>