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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么