CodeIgniter 给了我一个 Disallowed Key Characters 错误。即使在数据库中成功插入数据之后。这是我的代码。:
- 控制器:
类 applyleavectrl 扩展 CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('fill_in','fill'); //model fill in
$this->load->model('mdl_employee','emp');
$id = $this->session->userdata('id');
}
public function index()
{
$id = $this->session->userdata('id');
$this->form_validation->set_rules('leave_type', 'Leave Type', 'required|callback_check_select');
$this->form_validation->set_message('check_select', 'You need to select a leave type');
$this->form_validation->set_rules('from_date', 'From Date', 'required');
$this->form_validation->set_rules('to_date', 'To Date', 'required');
$this->form_validation->set_error_delimiters('<font size="1" face="helvetica" color="red">', '</font>');
if ($this->form_validation->run() == FALSE)
{
$data['employee_header_menus'] = $this->load->view('employee_header_menus', NULL, TRUE);
$data['employee_header_logout'] = $this->load->view('employee_header_logout', NULL, TRUE);
$data['leave_type'] = $this->fill->fill_leave_type();
$this->load->view('employee/applyleave', $data);
}
else
{
$id = $this->session->userdata('id');
$P1 = $this->input->post('leave_type');
$P2 = $this->input->post('from_date');
$P3 = $this->input->post('to_date');
$P4 = $this->input->post('comments');
$this->emp->insert_employee_leave($id, $P1, $P2, $P3, $P4);
redirect('employee/applyleavectrl');
}
}
function check_select($post_string)
{
return $post_string == '0' ? FALSE : TRUE;} }
模型
public function insert_employee_leave($id, $P1, $P2, $P3, $P4)
{
$value = array(
'empid' => $id,
'leave_type' => $P1,
'from_date' => $P2,
'to_date' => $P3,
'comments' => $P4);
$this->db->insert('employee_leave', $value);
}
观点是
<?php
$attributes = array('autocomplete' => "off");
echo form_open('employee/applyleavectrl', $attributes);
?>
<div class="row">
<div class="span3 offset2">
<label>Leave Type</label>
<select name="leave_type">
<option selected value="0">Select Leave Type</option>
<?php foreach($leave_type as $row): ?>
<option value="<?php echo $row['ID']; ?>"><?php echo $row['type']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="span3 offset2">
<label>From Date</label>
<input id="from_date" name="from_date" type="date">
</div>
</div>
<div class="row">
<div class="span3 offset2">
<label >Leave Balance</label>
<input name="leave_bal" id='leave_bal' type="text" disabled>
</div>
<div class="span3 offset2">
<label>To Date</label>
<input id="to_date" name="to_date" type="date">
</div>
</div>
<div class="row">
<div class="span2 offset2">
<a href="#history" data-toggle="modal">View Details</a>
</div>
</div>
</br>
<div class="row">
<div class="span3 offset2">
<label>Comments</label>
<textarea name="comments" rows="3"></textarea>
</div>
</div>
<div><?php echo validation_errors(); ?></div>
<div class="line"></div>
<div class="row">
<div class="span1 offset2">
<button type="submit" class="button-red">Apply</button>
</div>
</div>
<?php echo form_close(); ?>