简体   繁体   English

提交表单后,CodeIgniter不允许使用关键字符

[英]CodeIgniter Disallowed Key Characters after submitting the form

CodeIgniter is giving me a Disallowed Key Characters error. CodeIgniter给我一个不允许的关键字符错误。 even after successfully inserting data in database. 即使在数据库中成功插入数据之后。 here is my code.: 这是我的代码:

  • Controller: 控制器:

class applyleavectrl extends CI_Controller { 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;}   } 

model 模型

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);
}

and the view is 并且视图是

<?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(); ?>

if you are using 如果您正在使用

echo form_open('employee/applyleavectrl', $attributes); 

in your view then you should have a controller like employee not applyleavectrl. 在您看来,您应该有一个像雇员这样的控制器而不是applyleavectrl。

change it and let me know if its solved your problem or not. 更改它,让我知道它是否解决了您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM