Codeigniter房间预订表格验证

时间:2016-03-31 02:43:35

标签: php mysql codeigniter validation

我尝试使用form_validation制作预订房间的表单,以便在用户将数据输入表单时验证房间是否已经预订。我将输出显示在表格中。这是我的验证:

function add_room()
{
    $this->form_validation->set_rules('start', 'Start Date', 'required|is_unique[calendar.start]');
    $this->form_validation->set_rules('start_t', 'Start Time', 'required|is_unique[calendar.start_t]');
    $this->form_validation->set_rules('end_t', 'End Time', 'required|is_unique[calendar.end_t]');
    $this->form_validation->set_rules('room', 'Room', 'required|is_unique[calendar.room]');
    $this->form_validation->set_rules('title', 'Title', 'required|trim|xss_clean');
    $this->form_validation->set_rules('user', 'NRP', 'required|trim|xss_clean');
    $this->form_validation->set_rules('nama', 'Name', 'required|trim|xss_clean');
    $this->form_validation->set_rules('ext', 'EXT', 'required|trim|xss_clean');
    $this->form_validation->set_rules('topic', 'Topic', 'required|trim|xss_clean');
    $this->form_validation->set_rules('attend', 'Attendees', 'required|trim|xss_clean');

    if ($this->form_validation->run() == FALSE) {
        $this->form_validation->run('start_t');
    }
    elseif ($this->form_validation->run('start_t') == TRUE) {
        $this->form_validation->run('end_t');
    }
    elseif ($this->form_validation->run('end_t') == TRUE) {
        $this->form_validation->run('start');
    }
    elseif ($this->form_validation->run('start') == TRUE) {
        $this->form_validation->run('room');
    }
    elseif ($this->form_validation->run('room') == TRUE) {
        $this->form_validation->run();
    }
    elseif ($this->form_validation->run() == TRUE) {
        $this->calendar->add_room();
    } else {
        validation_errors();
        $this->conf->msg('danger');
    }
    redirect('calendar/meeting');


}

我知道我的代码很糟糕,我仍然不确定如何制作if结构。我想验证是否已预订RoomStart TimeEnd Time的{​​{1}}。如果已经预订,则验证将为false并显示Start Date。我并不擅长error message。事实上,我是这个编程的新手。那么,我如何在CI中建立一个合适的预订房间?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

将要验证的错误放在数组中

$ config = array(              数组('字段' =>' bk_r_type_id','标签' =>' bk_r_type_id名称','规则' ; =>' trim | required | max_length [100]')         );

    $this->form_validation->set_rules($config);