【问题标题】:Unable to access an error message corresponding to your field name JOB_CODE无法访问与您的字段名称 JOB_CODE 对应的错误消息
【发布时间】:2016-02-26 12:55:47
【问题描述】:

您好,我正在尝试验证我的数据库中是否存在现有的 job_code,我将插入一些东西,但我得到了这个

无法访问与您的字段名称对应的错误消息 JOB_CODE。

这是我的代码。

控制器

public function create(){

            $this->load->library('form_validation');
            $this->form_validation->set_rules('JOB_CODE','JOB_CODE','required|trim|callback_if_exist'); 
            $this->form_validation->set_rules('JOB_NAME','Job Name','required|trim');

            if($this->form_validation->run()){
                $this->load->model('Job_Titles_Model');
                $input = array(
                    'JOB_CODE' => $this->input->post('JOB_CODE'),
                    'JOB_NAME' => $this->input->post('JOB_NAME')
                    );
                $this->Job_Titles_Model->insert($input);
                $this->add_view();

            }else{
                $this->add_view();
            }

}

public function if_exist(){ 

        $this->load->library('form_validation');
        $this->load->model('Job_Titles_Model');

        if($this->Job_Titles_Model->validate_code()){
            return true;
        }else{
            $this->form_validation->set_message('if_exist','Job code already exists.');
            return false;
        }


    }

型号

public function validate_code(){

    $sql = "SELECT * FROM job_titles WHERE JOB_CODE =?";
    $data = array('JOB_CODE' => $this->input->post('JOB_CODE'));
    $query = $this->db->query($sql, $data);

    if($query->num_rows() == 0){
        return true;
    }else{
        return false;
    }

查看

    <?php

        echo form_open('Job_Titles/create');

        //echo "Job Title Code:";
        //echo form_input('JOB_CODE','', 'class ="field"');
        //echo "Job Title:";
        //echo form_input('JOB_TITLE','', 'class ="field"');
    ?>

    <p>
        <label class="field" for="JOB_CODE"><span>*</span>Job Code:</label>
        <input type = "text" name="JOB_CODE" class ="textbox-300">
    </p>
    <p>
        <label class="field" for="JOB_NAME"><span>*</span>Job Name:</label>
        <input type = "text" name="JOB_NAME" class ="textbox-300">
    </p>



    <?php
        echo form_submit('submit','Save');
        echo validation_errors();
        echo form_close();
    ?>

【问题讨论】:

    标签: php codeigniter hmvc


    【解决方案1】:
    $errs=array('password_check'=>'nice message');
    $this->form_validation->set_rules('password','password','callback_password_check',$errs);
    

    它似乎需要一个以函数名作为字段名的数组。 这是codeigniter 3.1.2

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 2015-12-16
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多