donglvlao8367 2018-02-14 09:21
浏览 38
已采纳

Codeigniter - 输入post方法是从多选字段中删除或清空发布数据

I am using Codeigniter 3.0.0 version

When trying access the value of a multi select drop down field named as subjecID[ ] using $this->input->post() method,it returning empty value. But When I am accessing the $_POST['subjectID'] I can see the value in the form of an array from the subjecID[ ] field. Even In older version of Codeigniter I was able to get the data as an array from the post. So, what might be the issue. Please tell me if is there any configurations to change?

Below is my controller function.

protected function rules() {
    $rules = array(
        array(
            'field' => 'name',
            'label' => $this->lang->line("teacher_name"),
            'rules' => 'trim|required|max_length[60]'
        ),
        array(
            'field' => 'subjectID',
            'label' => $this->lang->line("select_subject"),
            'rules' => 'required'
        )
    );
    return $rules;
}

public function add() {
            $this->data['subjects'] = $this->subject_create_m->get_subject();
    if($_POST) {
        $rules = $this->rules();
        $this->form_validation->set_rules($rules);
        if ($this->form_validation->run() == FALSE) {
            $this->data['form_validation'] = validation_errors();
            $this->data["subview"] = "teacher/add";
            $this->load->view('_layout_main', $this->data);
        } else {
            $array = array();
            $array['name'] = $this->input->post("name");
            $array['specialization'] = serialize($this->input->post('subjectID[]'));
            print_r($array);
        }
    } else {
        $this->data["subview"] = "teacher/add";
        $this->load->view('_layout_main', $this->data);
    }

}

Below is the Output I am getting by printing the post using the following code

print_r($this->input->post(NULL, FALSE));

Array ( [name] => sfgfdsgfsd [subjectID] => )

Because of this issue every time the validation is failing.

  • 写回答

5条回答 默认 最新

  • duanjie2940 2018-02-14 10:15
    关注

    try this 'field' => 'subjectID[]' instead of 'field' => 'subjectID' in the validation rules

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?