[英]Codeigniter room booking form validation
I'm trying to make a form for booking a room using form_validation
to validate whether the room is already booked or not when user input the data into the form. 我正在尝试使用
form_validation
制作一个预订房间的表单,以便在用户将数据输入表单时验证房间是否已经预订。 I showed the output into table. 我将输出显示到表中。 Here's my 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');
}
I know my code is awful, I'm still not sure how to make the if
structure. 我知道我的代码很糟糕,我仍然不确定如何制作
if
结构。 I want the validation check whether if the Room
at the Start Time
, End Time
and Start Date
is already booked or not. 我想验证是否已经预订了
Start Time
, End Time
和Start Date
的Room
。 If it's already booked the validation would be false and showing error message
. 如果已经预订,则验证将为false并显示
error message
。 I'm not really good at CI
. 我不太擅长
CI
。 In fact, I'm new in this programming stuff. 实际上,我是这个编程领域的新手。 So, how can I make a proper booking room in
CI
? 那么,我怎样才能在
CI
一个合适的预订室? Thanks for any help. 谢谢你的帮助。
Put the errors that you want to validate in an array 将要验证的错误放在数组中
$config = array( array('field' => 'bk_r_type_id', 'label' => 'bk_r_type_id Name', 'rules' => 'trim|required|max_length[100]') ); $ config = array(array('field'=>'bk_r_type_id','label'=>'bk_r_type_id Name','rules'=>'trim | required | max_length [100]'));
$this->form_validation->set_rules($config);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.