首页 文章

form_dropdown中的选定值在提交后不显示

提问于
浏览
2

我正在使用form_dropdown创建一个下拉框 . 它正常工作,因为正确列出了所有值,并在提交所选选项时实现了所需的类别过滤 . 但是在结果视图中,下拉列表显示“按类别过滤”,而我希望它显示$ selected_category,这是一个字符串 .

这是代码:

echo form_dropdown('company_category_ids', array(0 => ' Filter by Category ') + $unique_category_ids, $selected_category, ' id="category"');?>

感谢您的帮助或建议!

编辑 - 添加变量的内容:

$unique_category_ids:

Array( [58] => Coffee/Tea Accessories [179] => Food Storage [247] => Outdoor Trash)

$ selected类别可以是这三个项目中的任何一个(咖啡/茶配件,食品存储或户外垃圾) .

3 回答

  • 0

    我认为阵列中可能存在问题 . 我认为应该......

    $unique_category_ids = array("value_1" => "Filter by Size", "value_2" => "Filter by Color");
    $selected_category = "value_2"; //just for example
    echo form_dropdown('company_category_ids', array("value_3" => ' Filter by Category ') + $unique_category_ids, $selected_category, ' id="category"');
    
  • 0

    从我对CI的经验来看,似乎问题在于格式 . 这就是你拥有的:

    echo form_dropdown(
                'company_category_ids',  <----GOOD (this is the name of the Select tag)
                array(0 => ' Filter by Category '), <----WRONG this array should be your options
                $unique_category_ids, <---GOOD options
                $selected_category, <--GOOD
                'id="category"'); <---Good
    

    问题似乎是你有太多的参数 . 这应该最多采用4个参数 . 你的代码应该是这样的:

    $unique_category_ids = array(0 => ' Filter by Category ');
    $selected_category = '0';
    echo form_dropdown(
                'company_category_ids',
                $unique_category_ids, 
                $selected_category,
                'id="category"');
    
  • 2

    @jeemeesu感谢您的评论 . 我应该最初发布更完整的信息 . $selected_category 是一个文本字符串,由 $selected_category_id 定义 .

    $selected_category=$unique_category_ids[$selected_category_id];
    

    其中 $selected_category_id 是58,179或247.问题是我使用 $selected_category (咖啡/茶配件,食物储存或户外垃圾)而不是 $selected_category_id .

相关问题