[英]Codeigniter get selected values of form_multiselect
i'm working on a codeigniter website and i need to use form_multiselect the select shows fine but when i post it and i try to get the selected value on the controller when i do : 我正在一个Codeigniter网站上工作,我需要使用form_multiselect,选择显示很好,但是当我发布它时,我尝试在控制器上获取所选值:
$category = $this->input->get_post('category'); var_dump($category);
i get string(0) "". 我得到字符串(0)“”。
here is my codes : 这是我的代码:
View 视图
<?php echo form_multiselect('category[]', $categories); ?>
Controller 控制者
$data['categories'] = $this->blog_category_model->getblogcatDropDown($app_key);
$category = $this->input->get_post('category');
var_dump($category);
die;
Model 模型
public function getblogcatDropDown($app_key)
{
$query = $this->db->query('SELECT * FROM `webapp_blog_categories` WHERE `app_key`=('.$this->db->escape($app_key).') ORDER BY `id` ASC')->result();
$return[''] = 'Choose blog category';
foreach ($query as $row) {
$return[$row->id] = $row->cat_name;
}
return $return;
}
update 更新
when i use html select on the view : 当我在视图上使用html select时:
<select multiple name="tst[]">
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
it works fine , but the generated form not working 它工作正常,但生成的表单不起作用
can any one help me ? 谁能帮我 ? thanks
谢谢
Make sure the form method="post"
and simply check the whether the value is posted when you submit the form using developer tools. 确保使用
form method="post"
并简单地检查在使用开发人员工具提交表单时是否发布了该值。
for getting the value in controller. 获取控制器中的值。 it's simply.
很简单。
$category = $this->input->post('category');
$ category = $ this-> input-> post('category');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.