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条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮