我现在使用codeigniter,我想根据复选框值添加或删除记录。
如果“发送零”然后删除,或者如果“发送一个”值,则添加 怎么做这个任务?
<!-- Mail Menu Start -->
<div class="block">
<div class="titleSmal"><img src="<?= base_url(); ?>global/site/images/mailMenu.png" alt="" /></div>
<div class="content">
<form action="<?= base_url(); ?>mailinglist/send" method="post">
<fieldset class="form vote">
<legend> </legend>
<input id="e-mail" class="textBox med" name="ML_Email" value="<?= set_value('ML_Email')?>" /><span class="correct">accepted..</span><br />
<input id="subscription" type="radio" name="status" value="1" /><label for="answer1" class="label">subscription</label>
<input id="unsubscribe" type="radio" name="status" value="0" /><label for="answer2" class="label">unsubscribe</label><br />
</fieldset>
<input id="submit" type="submit" value="submit" class="button sml" />
</form>
</div>
</div><!-- Mail Menu End -->
控制器功能
function send() {
$this->form_validation->set_error_delimiters("<span class='incorrect'>", "</span>");
$this->form_validation->set_rules('ML_Email', 'البريد الالكتروني', 'trim|required|xss_clean|valid_email');
if ($this->form_validation->run() == false) {
$this->view('site/sending_error');
} else {
if($this->input->post('status')==1)
$this->mailinglist->send();
echo $this->db->last_query();
exit;
$this->view('theme/msg', $data);
}
}
}
模型功能
function send()
{
$this->db->set('ML_Email', $this->input->post('ML_Email'));
$this->db->set('status', $this->input->post('status'));
$this->db->set('ML_Date', date("l jS \o\F\ F Y H:i:s a"));
$this->db->insert('d_mailinglist');
return TRUE;
}
答案 0 :(得分:0)
只检查状态是1(插入)还是0(删除)
控制器
function send() {
$this->form_validation->set_error_delimiters("<span class='incorrect'>", "</span>");
$this->form_validation->set_rules('ML_Email', 'البريد الالكتروني', 'trim|required|xss_clean|valid_email');
if ($this->form_validation->run() == false)
{
$this->view('site/sending_error');
}
else
{
$this->mailinglist->send($this->input->post('status'));
$this->view('theme/msg', $data);
}
}
<强>模型强>
function send($status = null)
{
if( ! $status)
{
$this->db->where('ML_Email', $this->input->post('ML_Email'));
return $this->db->delete('d_mailinglist');
}
else
{
$this->db->set('ML_Email', $this->input->post('ML_Email'));
$this->db->set('status', $this->input->post('status'));
$this->db->set('ML_Date', date("l jS \o\F\ F Y H:i:s a"));
return $this->db->insert('d_mailinglist');
}
}