[英]CodeIgniter Disallowed Key Characters after submitting the form
CodeIgniter給我一個不允許的關鍵字符錯誤。 即使在數據庫中成功插入數據之后。 這是我的代碼:
class 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(); ?>
如果您正在使用
echo form_open('employee/applyleavectrl', $attributes);
在您看來,您應該有一個像雇員這樣的控制器而不是applyleavectrl。
更改它,讓我知道它是否解決了您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.