0

我现在使用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>&nbsp;</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;
}
4

1 回答 1

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');
    }

}
于 2012-09-15T15:06:26.290 回答