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. 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. I want the validation check whether if the Room
at the Start Time
, End Time
and Start Date
is already booked or not. If it's already booked the validation would be false and showing error message
. I'm not really good at CI
. In fact, I'm new in this programming stuff. So, how can I make a proper booking room in 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]') );
$this->form_validation->set_rules($config);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.