我遇到了表单验证的情况。对于如此简单的事情,我似乎无法弄清楚我的问题出在哪里,并且我在网上搜索了很长时间。如果返回 FALSE ,我的表单留空时应该form_error为每个字段抛出错误form_validation。但是,没有任何反应。当表单完全填写时,它会很好地插入到数据库中。我被困住了,我似乎无法弄清楚解决方案是什么。我的想法是代码在某处有拼写错误或表单设计不正确。
这是我的控制器:
function create_job()
{
// validate each form field
$this->form_validation->set_rules('repair_order', 'Repair Order', 'required');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('phone', 'Phone', 'required');
$this->form_validation->set_rules('vin', 'VIN', 'trim|required');
$this->form_validation->set_rules('year', 'Vehicle Year', 'trim|required|min_length[4]');
$this->form_validation->set_rules('make', 'Vehicle Make', 'required');
$this->form_validation->set_rules('model', 'Vehicle Model', 'required');
$this->form_validation->set_rules('start_date', 'Start Date', 'required');
$this->form_validation->set_rules('promise_date', 'Promise Date', 'required');
$this->form_validation->set_rules('body_hours', 'Body Labor Hours', 'required');
$this->form_validation->set_rules('paint_hours', 'Paint Labor Hours', 'required');
$this->form_validation->set_rules('body_tech', 'Body Technician', 'required');
$this->form_validation->set_rules('paint_tech', 'Paint Technician', 'required');
);
$this->db->insert('jobs', $data);
$this->session->set_flashdata("success", "New job has been successfully created.");
redirect('main');
}
else
{
redirect('jobs/new');
}
}
我是 CodeIgniter 的新手,只是想学习。如果有人能看到问题出在哪里并能指导我找到答案,我将不胜感激。
12345678_0001